×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Solving non-linear simultaneous equations

Solving non-linear simultaneous equations

Solving non-linear simultaneous equations

(OP)
How do you solve simultaneous non-linear equations in Matlab? I figured out I need to use fsolve or lsqnonlin, but I couldn't get the right answer using fsolve.

The equations that I need to solve are in this form:
y1=1-2cos(x1)+2cos(x2)-2cos(x3)=0.5
y2=-2cos(3*x1)+2cos(3*x2)-2cos(3*x3)=0
y3=-2cos(5*x1)+2cos(5*x2)-2cos(5*x3)=0

I wrote the m-file like this

function z = abc(x)
z(1)=0.5-2*cos(x(1))+2*cos(x(2))-2*cos(x(3))
z(2)=-2*cos(3*x(1))+2*cos(3*x(2))-2*cos(3*x(3))
z(3)=-2*cos(5*x(1))+2*cos(5*x(2))-2*cos(5*x(3))

and solve it using something like this (might be a bit wronf since I don't have the code here with me)
x0=[10;20;30;40]
options=optimset('tolfun',1.0e-008);
[x,fval]=fsolve[@zbc,x0,options]

I found that by using different initai guess x0 I'll get different answer, and the solutions never converge and Matlab keeps asking me to try different x0.  I have no idea what to choose, and the solutions I get never satisfy the given equations..

Can anyone help?

RE: Solving non-linear simultaneous equations

duwei

I tried your problem and didn't have any trouble.   Here's my answer and code.  Possibly the problem was in your call to fsolve.

x =

   10.2951
   21.2964
   29.9719
    0.0000


fval =

  1.0e-012 *

   -0.1032    0.2182    0.0437

function test

x0=[10;20;30;40]
options=optimset('tolfun',1.0e-008,'Display','iter');
[x,fval]=fsolve(@abc,x0,options)

function z = abc(x)
z(1)=0.5-2*cos(x(1))+2*cos(x(2))-2*cos(x(3));
z(2)=-2*cos(3*x(1))+2*cos(3*x(2))-2*cos(3*x(3));
z(3)=-2*cos(5*x(1))+2*cos(5*x(2))-2*cos(5*x(3));

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources