[Scilab-users] use of fsolve

Paul Carrico paul.carrico at free.fr
Tue Sep 3 08:19:28 CEST 2013


Dear All

 

Additional « silly » question : in the system herebellow, the solver finds 4
values  (1 per variable), but we know there’s 4 couples of results due to
the 2nd order ; of course the values depend on the starting point

 

I feel there’s a strategy in order to find all the solution but I don’t know
(or I don’t remember) how to proceed : any advice or reading in order to
solve such kind of system ?

 

Thanks

 

Paul

 

De : users-bounces at lists.scilab.org [mailto:users-bounces at lists.scilab.org]
De la part de Radovan Omorjan
Envoyé : lundi 2 septembre 2013 17:32
À : International users mailing list for Scilab.
Objet : Re: [Scilab-users] use of fsolve

 

Hello,

If you have some additional parameters in your function like this 

f(x,a,b..)=0
 
searching x, then use list() in fsolve() calling with the function name as
the first argument and parameters as subsequent arguments - like this f.e.

clc, clear
function f=foo(x, cst, R_)
    f(1) = (x(3) - cst(3))*(x(3) - x(1)) + (x(4) - cst(4))*(x(4) - x(2)) ;
    f(2) = (x(1) - cst(1))*(x(3) - x(1)) + (x(2) - cst(2))*(x(4) - x(2)) ;
    f(3) = (x(1) - cst(1))^2 + (x(2) - cst(2))^2 - R_(1)^2 ;
    f(4) = (x(3) - cst(3))^2 + (x(4) - cst(4))^2 - R_(2)^2 ;
endfunction
 
// constants
a = [106 ; 30 ; 54 ; 15] //a would be cst
b = [9 ; 9]              //b would be R_
 
//Initial guess 
 x1 = zeros(4,1)
 
// calculation using fsolve
// ind - termination indicator
// x - solution
// f - function values at the solution
[x,f,ind] = fsolve(x1,list(foo,a,b))

Regards,
Radovan

On 9/2/2013 3:32 PM, Carrico, Paul wrote:

Dear All
A basic question : what is the correct synthax is order to call the
constants cst and R_ in the foo function ? do I need to use "global"
variable ?
Thanks
Paul
function [f, ind]=foo(x, cst, R_, ind)
    f(1) = (x(3) - cst(3))*(x(3) - x(1)) + (x(4) - cst(4))*(x(4) - x(2)) ;
    f(2) = (x(1) - cst(1))*(x(3) - x(1)) + (x(2) - cst(2))*(x(4) - x(2)) ;
    f(3) = (x(1) - cst(1))^2 + (x(2) - cst(2))^2 - R_(1)^2 ;
    f(4) = (x(3) - cst(3))^2 + (x(4) - cst(4))^2 - R_(2)^2 ;
endfunction
 
function [f, ind]=foo2(x, ind)
    cst = [106 ; 30 ; 54 ; 15]
    R_ = [9 ; 9]
    f(1) = (x(3) - cst(3))*(x(3) - x(1)) + (x(4) - cst(4))*(x(4) - x(2)) ;
    f(2) = (x(1) - cst(1))*(x(3) - x(1)) + (x(2) - cst(2))*(x(4) - x(2)) ;
    f(3) = (x(1) - cst(1))^2 + (x(2) - cst(2))^2 - R_(1)^2 ;
    f(4) = (x(3) - cst(3))^2 + (x(4) - cst(4))^2 - R_(2)^2 ;
endfunction
 
// constants
cst = [106 ; 30 ; 54 ; 15]
R_ = [9 ; 9]
 
x0 = cst
x1 = zeros(4,1)
 
// calculationusing fsolve
T1 = fsolve(x0,foo)
T2 = fsolve(x1,foo2)

 

----------------------------------------------------------------------------
----
 
 
Le présent mail et ses pièces jointes sont confidentiels et destinés à la
personne ou aux personnes visée(s) ci-dessus. Si vous avez reçu cet e-mail
par erreur, veuillez contacter immédiatement l'expéditeur et effacer le
message de votre système. Toute divulgation, copie ou distribution de cet
e-mail est strictement interdite.
 
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error, please contact the sender and
delete the email from your system. If you are not the named addressee you
should not disseminate, distribute or copy this email.
 
 
 
 
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
 
 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20130903/637a7c96/attachment.htm>


More information about the users mailing list