[Scilab-users] Re : Re: Re : finding roots

paul.carrico at free.fr paul.carrico at free.fr
Sun Mar 30 22:51:57 CEST 2014


Thanks Rafael,

I've slightly modified your code, but I've an issue: the first root is found to 1.969 whereas it's close to 1.8751, leading to wrong results ... I do not figure out where's my mistake ... any suggestion ?

NB: after the 10th root, the roots seriously differ ...

Thanks

Paul


####################################################################
mode(0)

function y=fsol(x)
  y=cos(x). * cosh(x) + 1;
endfunction

// solve for first N solutions:
N=100;
x0 = [%pi/2 : %pi : %pi/2 + (N-1)*%pi]';
[nl,nc] = size(x0);
[Xsol]=fsolve(x0,fsol,,%eps);

// print the results
for i=1:nl
  printf("X(%d)= %8.15f\n",i,Xsol(i));
end


// verification
X_verif = fsol(Xsol); // should be equal/close to zero







----- Mail d'origine -----
De: Rafael Guerra <jrafaelbguerra at hotmail.com>
À: 'International users mailing list for Scilab.' <users at lists.scilab.org>
Envoyé: Sun, 30 Mar 2014 14:01:19 +0200 (CEST)
Objet: Re: [Scilab-users] Re :  finding roots

Hi Paul,

Please try the solution below using fsolve.

Could you let us know why do you want to solve that equation? Is it just for fun or is there an underlying physical problem?

PS:
I was looking for a new version of Scilab and found a donate button, Scilab needs our help.

Regards
Rafael Guerra


// Solution using fsolve (RG, 30-Mar-2014)

function y=fsol1(x)
  y=cos(x).*cosh(x)+1;
endfunction

// plot problem to find where to define initial value guesses:
x=-20:0.1:20;
y1=cos(x);
y2=-sech(x);
clf;
plot(x,y1,'b',x,y2,'r');

// solve for first 10 solutions:
N=10;
x0= linspace(%pi/2,%pi/2+(N-1)*%pi,N);
[Xsol]=fsolve(x0,fsol1);
for i=1:N
  printf("X(%2i)= +/- %8.6f\n",i,Xsol(i));
end


-----Original Message-----
From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of paul.carrico at free.fr
Sent: Sunday, March 30, 2014 10:48 AM
To: International users mailing list for Scilab.
Subject: [Scilab-users] Re : finding roots

Hooops I make a mistake :
cos(x)*cosh(x)+1=0

Paul

----- Mail d'origine -----
De: paul carrico <paul.carrico at free.fr>
À: International users mailing list for Scilab. <users at lists.scilab.org>
Envoyé: Sun, 30 Mar 2014 11:30:23 +0200 (CEST)
Objet: [Scilab-users] finding roots

Dear All

I would like to find the first 10 roots of the following equation :
cos(x)*cosh(x)-1=0

I think the solution is not trivial and need a specific development, isn't it ?

Cheers

Paul
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users




More information about the users mailing list