# Solving a parametererised equation that can't be done analytically

11 views (last 30 days)
Alexander Dearman on 10 Sep 2019
Answered: darova on 10 Sep 2019
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.

Walter Roberson on 10 Sep 2019
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.

#### 1 Comment

Alexander Dearman on 10 Sep 2019
Hi Walter,
I think I partially understand what you are saying.
Could you explain what you mean by anonymous functions?
Also the function I am expecting should be able to be fairly closely represented by a polynomial. The system I am modelling already has alot of uncertainty/assumptions, so I am not terribly bothered by a non-exact solution.
The function is not periodic either. I would hwoever like to be able to automate the process, as the other variables (c-l) are my design variables that I would like to explore by changing manually and re-iterating, or looking at 3D plots to gage their sensitivity.

darova on 10 Sep 2019
You can extract data from ezplot (Walter's answer)
See attached script