Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

how do i solve this non linear system?

Asked by Jaime on 4 Mar 2013

Hello, i must say that im not really good programing with matlab, i have this problem (i´ll explain it very fast):

1º I made a function that give me a vector made of real numbers i(1,6). 2º With that vector i, i would like to build and solve the next system:

f(1)= x(1)*x(2)*x(3)-i(1);
f(2)= x(1)*x(6)*x(3)-i(2);
f(3)= x(5)*x(2)*x(3)-i(3);
f(4)= x(5)*x(6)*x(3)-i(4);
f(5)= x(4)*x(2)*x(3)-i(5);
f(6)= x(4)*x(6)*x(3)-i(6);

For doing it, i tried the suggestion in this video:

http://www.youtube.com/watch?v=yN4gMygK8Uw

And if i do it, giving constant values to i (instead of using the vector i), i can solve the system, but when i introduce i, matlab says: undefined variable i... and several more errors.

I hope that everybody can understand what i mean, and i would be really gratefull if you can help me with it. Thanks you very much!

2 Comments

Brian B on 4 Mar 2013

Can you post more of your code?

Jaime on 4 Mar 2013

check this link: http://www.mathworks.es/es/help/optim/ug/fsolve.html

I want to do exactly the same as in example 1(scroll down after opening), but my problem is that myfun.m file looks like this:

function [f]=ecuaciones(x,i)
f(1)= x(1)*x(2)*x(3)-i(1)
f(2)= x(1)*x(6)*x(3)-i(2)
f(3)= x(5)*x(2)*x(3)-i(3)
f(4)= x(5)*x(6)*x(3)-i(4)
f(5)= x(4)*x(2)*x(3)-i(5)
f(6)= x(4)*x(6)*x(3)-i(6)

as you see, for building my system i also need i, not only x. So when i call it with fsolve it doesn´t work.

Jaime

Products

No products are associated with this question.

1 Answer

Answer by Brian B on 4 Mar 2013
Edited by Brian B on 4 Mar 2013
Accepted answer

fsolve will only pass in a single argument, so i will be undefined. Assuming you want to solve this equation for fixed values of i (say i = ibar) you can use an anonymous function like this:

 ibar = (1:6);
 ecuaciones_con_i = @(x) ecuaciones(x, ibar);

Then pass ecuaciones_con_i to fsolve (without a @, since it is already a function handle):

 xbar = fsolve(ecuaciones_con_i, x0);

1 Comment

Jaime on 4 Mar 2013

it worked very well now!, thanks you very much, you saved me! :p

Brian B

Contact us