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

Rafael Guerra jrafaelbguerra at hotmail.com
Fri Jan 12 20:54:03 CET 2018


Hi Hermes,

Find here below a simple solution using linear interpolation that works fine with your data but would need some further refinement for general arbitrary inputs.

// 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)

plot(t,LL(1,1:$),"-cya",t,LL(2,1:$),"-g",t,LL(3,1:$),"-r")
a=gca();

s= LL(3,:) - LL(1,:);
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));
y0 = interpln([t;LL(1,:)],t0);
plot(t0,y0,"b*") 

s= LL(3,:) - LL(2,:);
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));
y0 = interpln([t;LL(2,:)],t0);
plot(t0,y0,"black*") 
// END OF CODE

Regards,
Rafael





More information about the users mailing list