[Scilab-users] Find the points of intersection of two curves

Rafael Guerra jrafaelbguerra at hotmail.com
Tue Jan 16 23:37:53 CET 2018


Hi Hermes,

Check this solution out:

// START OF CODE
clear;
clf();

function Sys=F(x)
    x0=x(1);x1=x(2);
    Sys(1)=x1^2-x0*x1+x0^2-1;
    Sys(2)=sin(4*x1^2)+sin(5*x0^2);
endfunction

function D=Draghilev(x)
    x0=x(1);x1=x(2);x2=x(3);x00=ics(1);x01=ics(2);
    D=[8*x01^2*x1*cos(4*x1^2)-8*x00*x01*x1*cos(4*x1^2)+8*x00^2*x1*cos(4*x1^2)-8*x1*cos(4*x1^2)-2*sin(4*x01^2)*x1-2*sin(5*x00^2)*x1+x0*sin(4*x01^2)+x0*sin(5*x00^2);
    -sin(4*x01^2)*x1-sin(5*x00^2)*x1+2*x0*sin(4*x01^2)-10*x0*cos(5*x0^2)*x01^2+10*x0*cos(5*x0^2)*x00*x01+2*x0*sin(5*x00^2)-10*x0*cos(5*x0^2)*x00^2+10*x0*cos(5*x0^2);
    -8*x1^2*cos(4*x1^2)+16*x0*x1*cos(4*x1^2)-20*x0*cos(5*x0^2)*x1+10*x0^2*cos(5*x0^2)];
endfunction

function [dxdt]=odes(t,x)
    [dxdt]=Draghilev(x);
endfunction

ics=[0;1;1]
N=100;
smin=0.0;
smax=5;
h=0.0001;

step=smax/N;
t=smin:step:smax;
t0=0;
atol=h;
LL= ode("fix",ics,t0,t,atol,odes)

s= LL(3,:);
ym= s(1:$-1).*s(2:$);
z= find(ym <= 0);
t0 = t(z) - s(z).*(t(z+1)-t(z))./(s(z+1)-s(z));
x0 = interpln([t;LL(1,:)],t0);
y0 = interpln([t;LL(2,:)],t0);

param3d(LL(1,:), LL(2,:), 0 * LL(1,:), alpha=35, theta=45); // circle in the xy plane
e = gce();
e.foreground =17;
param3d(LL(1,:), LL(2,:), LL(3,:), alpha=35, theta=45) // parametric function in 3d-space
param3d(x0, y0, 0*x0, alpha=35, theta=45) // zero-crossings
e = gce();
e.line_mode = "off";
e.mark_mode = "on"
e.mark_style = 3;
e.mark_foreground =5 ;
// END OF CODE

Regards,
Rafael



More information about the users mailing list