How can I differentiate a non linear equation in Matlab
조회 수: 6 (최근 30일)
이전 댓글 표시
y = 5.0*10^-10*x +7.0*10^-25*x^3
I need to solve equation above for (x) , then differentiate (getting jacobian) for (y)
like:
sol ={solve(y,x)}
diff1= diff(sol,y)
Is that possible?
댓글 수: 0
채택된 답변
Walter Roberson
2015년 9월 23일
Yes, just use
syms x
y = 5.0*10^-10*x +7.0*10^-25*x^3
sol = solve(y, x)
diff(sol, y)
But remember that there are multiple solutions for x because there are three roots to the cubic.
댓글 수: 5
Walter Roberson
2015년 9월 25일
For those particular parameters, the Fortran code for the real root
Root1 = 0.52920000000000D14 * ((dble(52920 * y) + 0.42D2 * sqrt(dble
#(1587600 * y ** 2 + 42))) ** (0.2D1 / 0.3D1) + 0.42D2) * (dble(y)
#+ sqrt(dble(1587600 * y ** 2 + 42)) / 0.1260D4) * (dble(52920 * y)
# + 0.42D2 * sqrt(dble(1587600 * y ** 2 + 42))) ** (-0.4D1 / 0.3D1)
# * dble((1587600 * y ** 2 + 42) ** (-0.1D1 / 0.2D1))
Part of the difficulty is that you have not restricted yourself to real roots. The code generation tools I use for Fortran have trouble with long expressions that involve complex numbers :(
I did some tests with
y == 5*10^(-10)*x +7*10^(-25)*x^3 + A * x^4
and it appears to me that Fortran does not have the precision needed to evaluate the roots.
Is it a particular 4-degree polynomial that you will be working with, or do you need to run through a bunch of them?
Walter Roberson
2015년 9월 25일
You mean like
fortran(S,'file',fileName)
You can construct the general pattern for order 3 equations
syms x y A B C D
z = y == A * x.^3 + B * x.^2 + C * x + D;
sol = solve(z,y);
dsol = simplify(diff(sol(1),y));
fortran(dsol, 'filename', 'dinvcubic.f')
Once generated you would only need to invoke it after assigning appropriate values to A, B, C, D
The same technique can be used for order 4, but the expressions get very long, and the code might not have enough precision for accurate answers for some ranges.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!