Thanks ... indeed much more stable .. Paul
-----Message d'origine----- De : users [mailto:[email protected]] De la part de Rafael Guerra Envoyé : dimanche 30 mars 2014 23:34 À : 'International users mailing list for Scilab.' Objet : [Scilab-users] RE(2): finding roots Hi Paul, The new code here below does not show any such problem for all N solutions I tried. Note that your problem: cos(x) .* cosh(x) + 1 = 0; is equivalent to: cos(x) + sech(x) = 0. The latter form seems to be numerically more stable. Regards, Rafael // Solution using fsolve (RG, 30-Mar-2014) function y=fsol1(x) y = cos(x) + sech(x); endfunction clc; // solve for first N solutions: N=25; x0= linspace(%pi/2,%pi/2+(N-1)*%pi,N); // plot problem to find where to define initial value guesses: x=-x0($):0.1:x0($); y1=cos(x); y2=-sech(x); clf; plot(x,y1,'b',x,y2,'r'); Xsol=fsolve(x0,fsol1); Y_verif = fsol1(Xsol); // should be equal/close to zero printf("\n"); for i=1:N printf("X(%2i)= +/- %8.6f .....",i,Xsol(i)); printf("Y(%2i)= +/- %8.6f\n",i,Y_verif(i)); end plot([-Xsol; Xsol],cos([-Xsol; Xsol]),"black*") -----Original Message----- From: users [mailto:[email protected]] On Behalf Of [email protected] Sent: Sunday, March 30, 2014 9:53 PM To: International users mailing list for Scilab. Subject: [Scilab-users] Re : Re: Re : finding roots 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 <[email protected]> À: 'International users mailing list for Scilab.' <[email protected]> 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:[email protected]] On Behalf Of [email protected] 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 <[email protected]> À: International users mailing list for Scilab. <[email protected]> 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 [email protected] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [email protected] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [email protected] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [email protected] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [email protected] http://lists.scilab.org/mailman/listinfo/users --- Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com _______________________________________________ users mailing list [email protected] http://lists.scilab.org/mailman/listinfo/users
