[Scilab-users] Using the Function fsolve

Samuel Gougeon sgougeon at free.fr
Sun Aug 28 23:04:55 CEST 2016


Le 28/08/2016 22:48, Robert Sherry a écrit :
> Samuel,
>
> Thanks for the response. While the example, I showed is linear, the 
> equations I want to solve are not. I am thinking I need a third 
> function which returns a vector. Am I on the right track?
.
Then it would have been great to post a non-linear sample with sin(x), 
etc ;)
Only one function -- but vectorized -- is required. Here is an example 
(non-linear :):
function Z = f(u)
   x = u(1)
   y = u(2)
    Z = [ sin(x)-y+3
          cos(y)+x-2
        ]
endfunction
s = fsolve([0 0]',f)
[ sin(s(1))-s(2)+3  cos(s(2))+s(1)-2]  // Check

--> function Z = f(u)
   >   x = u(1)
   >   y = u(2)
   >    Z = [ sin(x)-y+3
   >          cos(y)+x-2
   >        ]
   > endfunction

--> s = fsolve([0 0]',f)
  s  =
    2.9999999
    3.1411201


--> [ sin(s(1))-s(2)+3  cos(s(2))+s(1)-2]  // Check
  ans  =
    4.441D-16  -1.332D-15

// Samuel

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


More information about the users mailing list