solving system of non linear equations using fsolve by converting symbolic expressions

조회 수: 1 (최근 30일)
Hi. I want to solve a system of non linear equations in 3 variables using fsolve. But the equations which i get would be in the symbolic form. My code somewhat looks like this:
%file to create equations
syms c d e x;
R=(1+(1-c-d-e+c*x^2+d*x^3+e*x^4))*(2*c+6*d*x+12*e*x^2) + (2*c*x+3*d*x^2+4*e*x^3)^2 -(1-c-d-e+c*x^2+d*x^3+e*x^4);
eq_1=int(R*x^3,x,0,1);
eq_2=int(R*x^2,x,0,1);
eq_3=int(R*x,x,0,1);
Now, I want to solve above equations using fsolve. for that i have created a separate function file, to where i copy the three equations from the command window after running this script file. what i want to know is that, is there any way to update these three equations automatically directly to the function file which i have created.
  댓글 수: 2
Matt J
Matt J 2021년 11월 5일
편집: Matt J 2021년 11월 5일
First of all, they don't seem to be equations because they are not set equal to anything. Do you intend to set them equal to zero?
Secondly, eq_1 and eq_2 are identical.
Walter Roberson
Walter Roberson 2021년 11월 6일
Symbolic toolbox recognizes pure expressions with no equality in them, as implicit equality with 0. This allows you to easily do things like E = lhs(eq_1) - rhs(eq_1); fplot(E); solve(E) %solutions are places where E is 0

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 5일
Here is the solution:
syms c d e x;
R=(1+(1-c-d-e+c*x^2+d*x^3+e*x^4))*(2*c+6*d*x+12*e*x^2) + (2*c*x+3*d*x^2+4*e*x^3)^2 -(1-c-d-e+c*x^2+d*x^3+e*x^4);
eq(1)=int(R*x^3,x,0,1);
eq(2)=int(R*x^3,x,0,1);
eq(3)=int(R*x^2,x,0,1);
SOL = solve(eq==0);
c = double(SOL.c)
c =
1.0e+02 * 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0022 + 0.0000i -0.0369 - 0.0472i -0.0369 + 0.0472i 2.6212 + 0.0000i
d = double(SOL.d)
d =
1.0e+02 * 1.1092 + 0.0000i -0.2601 + 0.0000i -0.0001 + 0.0000i 0.0303 + 0.0183i 0.0303 - 0.0183i -2.2801 + 0.0000i
e = double(SOL.e)
e = 6×1
-214.8882 18.1132 0 0 0 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by