Solving a parametererised equation that can't be done analytically
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I have the following problem.
I have the following function where each side of the equation is a differnet expression but involving the same variables. Somthing like this:
eqn = (expression(a,b) == expression2(a,b))
I would like to get a as a funciton of b or visaversa.
a = f(b)
or
b = f(a)
From the equation I have I do not think this can be solved analytically, which is supported by "solve()" function not working.
When i try to use vpasolve() it does not work as I have described the equation using symbolic variables and would like a parametrised solution.
I'd rather not share my code directly for a few reasons (main one as it is a big mess)
This is how the code basically looks:
syms a b c d e f g h k l
% First function
Mf(a,b,c,d,e,f,g,h,k,l) = (c*d*(1/((e+f*a+g*b)^h))+(1/((e-f*a-g*b)^h))*k) + a*l*500
%Second Function
Mr(a,b,c,d,e,f,g,h,k,l) = (c*d*(1/((e+f*a*5+g*b*2)^h))+(1/((e-f*a*5-g*b*2)^h))*k*4) +b*l*600
% Mf and Mr are equal, hence define a new equation where that is the case, and pass values to all variables except a and b.
eqn = (Mf(a,b,1,2,3,4,5,1.4,7,8) == Mr(a,b,1,2,3,4,5,1.4,7,8))
%-----------------------------------------Lets try and get a solution-------------------------
solution = solve(eqn, a) % this fails to find an explicit solution. As I dont think it is possible analytically.
%ok, try this:
solution = vpasolve(eqn,a) % This gives the following error:
% Error using mupadengine/feval (line 187)
% Symbolic parameters not supported in nonpolynomial equations.
%
% Error in sym/vpasolve (line 172)
% sol = eng.feval('symobj::vpasolve',eqns,vars,X0);
Is there another way to get a solution. I need a relation between a and b so that I may then get a function, say M = f(a) or M = f(b), which is equivalent to Mf or Mr but is only a function of one variable, as the constraint is that Mf and Mr are equal.
The solution can be numeric, and can even be limited e.g. a = f(b) for -1<b<1.
댓글 수: 0
답변 (2개)
Walter Roberson
2019년 9월 10일
The only general solution (valid over continuous expressions, not valid of discontinuities) is to create a function of one variable that uses anonymous functions to solve for the other variable in (Ml - Mr)==0 with fsolve()
For some functions it might be useful to approximate the non-linear functions by a taylor series to arrive at an approximating polynomial that you can then apply numeric methods to -- or calculate exact solutions for if you approximate by degree 4 or less. Sometimes this kind of technique can help provide order-of-magnitude values to use for initial values for numeric solutions. But there are plenty of functions that the approximation would just be too weak -- for example taylor series of periodic trig functions get too far away from the real solution beyond one period of the function.
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!