Solving non linear equations in a 4x2 matrix

Hello,
I am trying to calculate the roots of a system of non-linear equations:
[1 1;x y;x^2 y^2;x^3 y^3]*[a;b]=[2;0;2/3;0]
x,y,a, and b are unknowns
When i try to solve the system it gives ans=struct with fields.
can someone help out

 Réponse acceptée

If you have symbolic toolbox, you can use solve() function
syms x y a b
eq = [1 1;x y;x^2 y^2;x^3 y^3]*[a;b]==[2;0;2/3;0];
sol = solve(eq);
The system have two solutions. sol is a struct. You can access the solution like this
>> sol.x
ans =
3^(1/2)/3
-3^(1/2)/3
>> sol.y
ans =
-3^(1/2)/3
3^(1/2)/3
>> sol.a
ans =
1
1
>> sol.b
ans =
1
1

4 commentaires

Ali Awada
Ali Awada le 9 Oct 2020
thanks for clarifying it! much appreciated!
as a side question is there a way to display the solution instead of accessing it one by one?
You can do something like this
syms x y a b
eq = [1 1;x y;x^2 y^2;x^3 y^3]*[a;b]==[2;0;2/3;0];
sol = struct2cell(solve(eq));
sol = [sol{:}];
first_sol = sol(1,:);
second_sol = sol(2,:);
Ali Awada
Ali Awada le 9 Oct 2020
Thanks!
Ameer Hamza
Ameer Hamza le 9 Oct 2020
I am glad to be of help!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by