[Scilab-users] use of fsolve

Radovan Omorjan omorr at uns.ac.rs
Mon Sep 2 17:32:14 CEST 2013


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)
>
> //calculationusingfsolve
> 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/20130902/6b6e49fd/attachment.htm>


More information about the users mailing list