Solving composite equations with symbolic toolbox

조회 수: 1 (최근 30일)
Nicholas Davis
Nicholas Davis 2021년 6월 1일
댓글: Sulaymon Eshkabilov 2021년 6월 2일
Hi all,
I have a very simple code written to solve for two variables within two equations. My main variables are A and B, which are renamed to AR and BR later in the program. My constants are w, g, alphaL, and p. The initial equation is quadratic and thus will have two answers. I want each of these answers to be plugged into a new equation, a cubic equation, to therefore produce 6 differing solutions. I am not sure how to do this via symbolic toolbox, so any help would be seriously appreciated. Thanks!
syms A B w g alphaL p % w = (mu - V0)
eqn = B*(A + B)*(2*w - g*(A + 2*B)) - alphaL^2 == 0;
AR = solve(eqn,A);
neqn = -4*(B - p)*(AR + B - p)*(2*w - g*(AR + 2*B + p)) == 0;
BR = solve(neqn,B);
  댓글 수: 3
Nicholas Davis
Nicholas Davis 2021년 6월 1일
Hi Torsten.
I wasn't sure what approach to take as this was my first time with symbolic toolbox. The goal here was to start with the first equation and solve for A. The second equation was to have these solutions to A plugged into it to produce solutions for B.
John D'Errico
John D'Errico 2021년 6월 1일
You CAN do it that way, at least, in this case, you can. However, the symbolic toolbox is better used to solve the two equations simultaneously. It has no problem with understanding there should be 6 solutions. @Sulaymon Eshkabilov shows how to do that.

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 1일
Hi,
Here is the corrected code with the symbolic solutions (A, B) of the two equations:
clearvars
syms A B w g alphaL p AR
eqn1 = B*(A + B)*(2*w - g*(A + 2*B)) - alphaL^2 == 0;
eqn2 = -4*(B - p)*(AR + B - p)*(2*w - g*(AR + 2*B + p)) == 0;
SOL = solve(eqn1, eqn2,A, B);
A_solution=SOL.A;
B_solution=SOL.B;
Good luck.
  댓글 수: 2
Nicholas Davis
Nicholas Davis 2021년 6월 2일
This works amazingly Sulaymon! So, when used in the way that you have it written, the solve command can solve for both equations simulatenously? Also, can you explain the function of the last 2 lines?
Thanks for the help!
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 2일
Most welcome!
The last two lines are separation of solutions of A and B variables.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by