¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Scilab test


 
Edited

Draw a conic :

My equation is of the form :

axx + bxy + cyy + dx + ey + f = z where z = 0

I would like to get the (x,y) coordinates of all points on the ellipse where z=0

For example my function with the Scilab code is:

function [z] = fct(x,y)
    z = -0.04088*x^2 - 0.10063*y^2 - 0.21767*x + 0.44632*y + 0.04286*x*y
endfunction

I set the working space with:

x=-10:10; y=-10:10;

I draw my ellipse with:

fcontour2d(x, y, fct, [0,0], style=[9,9])

Now i will get all points ((x,y) coordinates) of the plotted ellipse where z=0

Solution (works with Scilab-5.5.2 under Windows ; does not work with Scilab 6.1.0 under Linux):

Here is my source code for Scilab:

// conic function

function [z]=fct(x,y)

z=-0.04088*x^2-0.10063*y^2-0.21767*x+0.44632*y+0.04286*x*y

endfunction

// plane surface z=0

function [z]=f(x,y)

z=0*x*y

endfunction

// working space

x=-10:10;y=-10:10;

// we draw the 2d ellipse from the conic function where z=0

fcontour2d(x,y,fct,[0,0],style=[9,9])

// we write a function to find the intersection between the conic and the place surface

function [Y]=coniques(X) , Y=[fct(X(1),X(2)),f(X(1),X(2))] endfunction

for i=-10:0.1:10 // for each offset off the y axis (with i from -10 to 10 with a step of 0.1)

rep=fsolve([-10,i],coniques); // we find the coordinates (rep(1)=x, rep(2)=y) of the first point of intersection (search from the left to the right)

xpolys(rep(1),rep(2),-1) // we plot the point on the chart

rep=fsolve([10,i],coniques); // we find the coordinates (rep(1)=x, rep(2)=y) of the second point of intersection (search from the right to the left)

xpolys(rep(1),rep(2),-1) // we plot the point on the chart

end

?

Join [email protected] to automatically receive all group messages.