[Scilab-users] find a zero of a system of nonlinear functions
CRETE Denis
denis.crete at thalesgroup.com
Tue Nov 28 11:31:13 CET 2017
Hello
The first argument in fsolve is not the range of the variable in which the solution is looked for. Instead it is a guessed value:
// Start of code
function y = poly_cubic(x)
y = 3 - 10*x + 2*x^2 + 3*x^3;
endfunction
yr=fsolve(1.3,poly_cubic,%eps)
// yr = 1.3027756
yr=fsolve(-2,poly_cubic,%eps)
// yr = - 2.3027756
yr=fsolve(0,poly_cubic,%eps)
// yr = 0.3333333
// End of code
By the way, for polynoms, it is more straightforward to do :
p=[3 2 -10 3]; roots(p)
// ans =
- 2.3027756
1.3027756
0.3333333
HTH
Denis
-----Message d'origine-----
De : users [mailto:users-bounces at lists.scilab.org] De la part de Hermes
Envoyé : mardi 28 novembre 2017 11:13
À : users at lists.scilab.org
Objet : [Scilab-users] find a zero of a system of nonlinear functions
fsolve
I find a zero of a system of nonlinear functions:
y = 3 - 10 * x + 2 * x ^ 2 + 3 * x ^ 3 in the range x = -3: 0.01: 3
but fsolve returns as a solution a vector (in the scrip yr) of the same size as x.
I have varied the precision tolerance h to several values 1.d-3 to% eps. but I always get that infinity of solutions.
the only solution that I found is shown in the script.
Is it possible to improve this?
funcprot(0);
function y = poly_cubic(x)
y = 3 - 10*x + 2*x^2 + 3*x^3;
endfunction
x=-3:0.01:3;
clf()
plot(x,poly_cubic);
disp("-2.3027756 0.3333333 1.3027756 ", "Roots to y = 3 - 10*x + 2*x^2 +
3*x^3")
h=%eps;
yr=fsolve(x,poly_cubic,h)
RR=strtod(unique(string(yr)));
RR=gsort(RR,'g','i');//sort the elements of the array RR in the increasing order.
disp(RR,"Roots values f(x)")
plot(RR,poly_cubic,"ro")
--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
More information about the users
mailing list