System of nonliner equations with symbolic variables

조회 수: 3 (최근 30일)
Jan Pluhar
Jan Pluhar 2020년 5월 23일
댓글: Star Strider 2020년 5월 25일
Hi there,
I would like to ask you how to solve a system of nonlinear equations while using symbolic variables.
I have two equations that I need to solve:
eqT = 10*lamT^13*lamZ^13 - 10/lamT^13 - 10*lamT^2*lamZ
eqZ = 10*lamT^13*lamZ^13 - 10/lamZ^13 - 5*lamT^2*lamZ
where lamT and lamZ are symbolic.
I was trying to search for it and most times I have found to use matlabFunction and fsolve. But it doesn't work for me. Probably I understand it wrong or maybe I am doing another mistake.
fun = matlabFunction(eqT, eqZ)
eqsol = fsolve(fun,[1 1])
Can you please help me and explain me what I am doing wrong.
Thank you very much
P.S.: it is not possible not to use symbolic variables. They are used for some derivations before. Also it is not possible to rewrite the equations manually because they are to be solved many times in for cycle with different constants.

채택된 답변

Star Strider
Star Strider 2020년 5월 23일
The code needs a few adjustments:
syms lamT lamZ
eqT = 10*lamT^13*lamZ^13 - 10/lamT^13 - 10*lamT^2*lamZ;
eqZ = 10*lamT^13*lamZ^13 - 10/lamZ^13 - 5*lamT^2*lamZ;
fun = matlabFunction([eqT; eqZ], 'Vars',{[lamT lamZ]})
eqsol = fsolve(fun,[1 1])
producing:
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
eqsol =
1.046382084316825 0.992821241450066
The approach concatenates ‘eqT’ and ‘eqZ’ to creatd a (2x1) matrix, and combine ‘lamT’ and ’lamZ’ into the ‘in1’ parameter vector that fsolve requires. Then fsolve does the rest.
.
  댓글 수: 4
Jan Pluhar
Jan Pluhar 2020년 5월 25일
Thank you again for your answer. If you would like to know what I'm doing than it is a simulation of inflation and extension of a a cylindric pipe, similar to veins. Variable P represents pressure and lamT,Z represent strain (prolongation/shortening) in some directions.
Unfortunately, I was trying to implement your solution and it doesn't work the way it should. Finally, I've decided to find my solution by using Maple following my professor's steps. The initial intention was to do that by using Matlab because I do not like Maple and also I wanted to learn to work with symbolic variables. Finally, I've given up and did it the other way.
To do that in Matlab is not needed anymore, however, if you were interested in finding the solution, I would be glad for your help to find the right solution.
In the eqsol = fsolve ... should be Pvect(i) instead of Pvect(n). And the results should be:
lamT = 1 nonlinearly ascending to 2.8
lamZ = 1 nonlinearly descending to 0.6
I see that the problem is somewhere in fsolve and do not know how to deal with it. You can try on your own, otherwise I think that it is correct.
If you found the solution, I would be glad. But as I wrote it is not necessary anymore.
Thank you for your answers,
I was glad that you tried to help me
Star Strider
Star Strider 2020년 5월 25일
As always, my pleasure!
I mistyped the ‘Pvect’ subscript. My apologies.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by