Solving a System of Equations with syms

Hello,
I have a system of 10 equations and 14 unknowns. I want to solve this system of equations for 6 particular unknowns in terms of the other unknowns.
When I use solve(Equations==0) then it successfully solves for 10 unknowns in terms of the other 4 unknowns. However, I can't control which 10 unknowns MATLAB solves for.
When I try to specify 6 of the unknowns MATLAB solves for and use solve(Equations==0,x1,x2,x3,x4,x5,x6) then I get an empty matrix as my answer.
Can someone please tell me how I can correctly specify the 6 unknowns that I want MATLAB to solve for?
Thank you, Kevin

3 Comments

Said another way, I want to compress the system of 10 equations and 14 unknowns to a system of 4 equations and 8 unknowns (where I can specify the 6 unknowns I don't want in the compressed system).
Perhaps the equations are not solvable with respect to those 6 variables.
Seems like I have to specify all 10 substitution variables for solving the other 4 variables, but I think that is ok for my purpose.
When I used, solve(Equations==0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10), then that successfully solves for x11,x12,x13,x14.
Do you know is there a way to specify the substitution variables as a matrix? Doing
XSubsitute = [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
solve(Equations==0,XSubstitute)
produces an empty matrix as my answer.
I really need to be able to specify the substitution variables as the elements in the matrix to be able to apply my code for a general problem.

Sign in to comment.

 Accepted Answer

XSubstitute = {x1,x2,x3,x4,x5,x6,x7,x8,x9,x10}
solve(Equations==0,XSubstitute{:})

6 Comments

Thanks that does work, but I should clarify what I meant. I already have the substitution variables stored in a 1x10 sym array called XSubstitute, which is an input to the function I'm writing. Is there any way to convert the 1x10 sym array to a 1x10 cell within my function before I use the solve function?
vars = num2cell(XSubstitute);
solve(Equations==0, vars{:});
Thanks, that works. Using answer = solve(Equations==0, vars{:}) return a 1x1 struct, which has 10 fields. I'm only interested in the first N fields of answer. Is there a way to extract the first N fields into a new variable?
Also is there a way to simplify the values for the first N fields using the MATLAB "simplify" command before extracting the first N fields into a new variable?
You could work with struct2cell()
The problem with this is that I lose the field names then. There's no way to directly extract the first N fields and values from a struct and then put in another struct? Something like answer2 = answer{1:N}?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!