Solving system of nonlinear euations

In mathematica we use the command NSolve[{x^2 + y^3 == 1, 2 x + 3 y == 4}, {x, y}, Reals] without needing any initial guess to solve a system of non-linear equations. I need the same command in Matlab to solve system of non-linear equations BUT without needing the initial guess. THANKS

4 Comments

What's the problem with assigning initial guesses? Can't you make them up with some knowledge of the system you're trying to solve?
I dont have any initial guess as i am trying to solve a system of 4 equations and 4 four variable, and each equation is containing 24 nonlinear terms. Can you please suggest me some way in Matlab, as i am new in matlab. Thanks
I don't think you can. You'll have to use fsolve, which requires an initial guess. If it's a mathematical exercise, I'd go with an array of zeros; otherwise, if the eqn represent a physical system, you can use some reasonable values (e.g. mass is usually >= 0).
Actually to use fsolve we need to make another m file for the function, in my case ceofficients of variables in equations depend on many other values in my program . Can we make function which is called by fsolve within the program.

Sign in to comment.

 Accepted Answer

syms x y
[x,y] = vpasolve(x^2 + y^3 == 1, 2*x + 3*y == 4, x,y)

2 Comments

I have used the above command but i am getting this error Expression or statement is incorrect--possibly unbalanced (, {, or [.
My Codes were the following
syms x y z s [x,y,z,s] = vpasolve(Aphi(n/8).*x+Bphi(n/8).*y+Aphi(n/8).*z+Bphi(n/8).*s^2+Ephi(n/8).*x^2+Ephi(n/8).*y^2+Ephi(n/8).*z^2+Ephi(n/8).*s^2+Iphi(n/8).*x*z+Jphi(n/8).*y*s+Kphi(n/8).*x*s+Kphi(n/8).*y*s+Mphi(n/8).*y*z^2 +Mphi(n/8).*y*s^2+Mphi(n/8).*s*x^2+Mphi(n/8).*z*y^2+Ophi(n/8).*x*z^2+Ophi(n/8).*x*s^2+Ophi(n/8).*z*x^2+Ophi(n/8).*z*y^2-Uphi(n/8).*x^2*z^2-Uphi(n/8).*x^2*s^2-Uphi(n/8).*y^2*z^2-Uphi(n/8).*y^2*s^2 ==Vphi(n/8), Aphi(n+n/8).*x+Bphi(n+n/8).*y+Aphi(n+n/8).*z+Bphi(n+n/8).*s^2+Ephi(n+n/8).*x^2+Ephi(n+n/8).*y^2+Ephi(n+n/8).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Ophi(n/16).*x*z^2+Ophi(n/16).*x*s^2+Ophi(n/16).*z*x^2+Ophi(n/16).*z*y^2-Uphi(n/16).*x^2*z^2-Uphi(n/16).*x^2*s^2-Uphi(n/16).*y^2*z^2-Uphi(n/16).*y^2*s^2 ==Vphi(n/16), , x,y,z,s)
I see an extra comma (,) in the very last part of the code. ,,x,y,z,s --- remove one comma. It also seems that you have to define Aphi, Bphi........ with n

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!