Error using the solve command
Show older comments
Hello, I'm currently using the solve command to try and solve a system of 2 equations with 2 unknowns.
The code I'm using looks like this:
syms h Tf;
s=solve('((Tw1(1)-Ti)/(Tf-Ti))=1-exp(((h^2)*alpha*t1)/(k^2))*erfc((h*sqrt(alpha*t1))/k), ((Tw2(1)-Ti)/Tf-Ti)=1-exp(((h^2)*alpha*t2)/(k^2))*erfc((h*sqrt(alpha*t2))/k)',h,Tf)
Tw1(1), Ti, alpha, t1, t2, and k are all known values in this.
It is returning an error message stating:
"Warning: Explicit solution could not be found.
> In solve at 81
In datareduction at 53
sol =
[ empty sym ]"
I know that there should be a solution to this system, as it has been proven before, I am just unable to figure out the proper way to solve it in MATLAB. Any help is greatly appreciated.
Thank you.
2 Comments
Walter Roberson
on 12 Jun 2013
What are Tw2(1) and Tw1(1) intended to be?
You have them appearing in quoted strings, so they will be interpreted according to MuPAD syntax instead of MATLAB syntax. In MuPAD, () is only used for function parameter, not for indexing. Tw2(1) inside a quoted string means the function Tw2, applied with the parameter 1. If you wanted Tw2 subscript 1, you would use Tw2[1] inside quoted strings.
Joshua
on 12 Jun 2013
Answers (1)
Alan Weiss
on 11 Jun 2013
Edited: Alan Weiss
on 11 Jun 2013
1 vote
You cannot really expect a symbolic solution to such a problem involving, as it does, the complementary error function. Instead, you can try a numeric solution for given values of your other parameters by using the fsolve function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
6 Comments
Joshua
on 11 Jun 2013
Roger Stafford
on 11 Jun 2013
I see what may be an error in your equations. On the two left sides you have:
((Tw1(1)-Ti)/(Tf-Ti))
((Tw2(1)-Ti)/Tf-Ti)
In the first you subtract Ti from Tf first, then divide by the difference; in the second you divide by Tf first, then subtract Ti. I suspect you meant them both to subtract first, then divide. Am I right?
As Alan says, there is no reason to expect that 'solve' will always succeed in finding explicit solutions to implicit equations. This is similar to finding indefinite integrals in calculus. As you must have discovered, there are a great many indefinite integrals without known explicit solutions. For that reason, you may often be forced into using numerical methods in such cases.
Joshua
on 12 Jun 2013
Roger Stafford
on 12 Jun 2013
Here's some advice for a possibly easier numerical approach. Your unknowns are presumably Tf and h. In both equations you can solve for Tf in terms of h. Setting these two expressions in h equal to each other will give you a single equation in the single unknown h with Tf eliminated. It is easier numerically to solve for one unknown. A simple plot over the appropriate range of h can quickly identify the approximate value or values of its roots and the 'fzero' function can then use these as estimates to make them precise. Then you can directly evaluate the corresponding Tf using either of the previous equations.
Walter Roberson
on 12 Jun 2013
The representation of Tf in terms of h is rather messy: it involves finding the roots of a non-polynomial expression, one of terms of which involves a value which is the root of another non-polynomial expression. With a structure like that, accuracy would tend to be a big problem: the default MuPAD 10 digits of calculation is likely not going to be enough.
Roger Stafford
on 12 Jun 2013
I disagree Walter. There is no polynomial involved. The first equation has this form:
k1/(Tf-k2) = 1-exp((k3*h)^2)*erfc(k3*h)
where I have combined some of the parameters into k1, k2, and k3. It is readily solved for Tf in terms of h:
Tf = k2 + k1/(1-exp((k3*h)^2)*erfc(k3*h))
Combined with a similar expression derived from the second equation this will give a single equation in a single unknown, h. However I doubt if there exists an explicit solution to this single equation, and hence it must be solved numerically, presumably with 'fzero', for each different set of given parameters.
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!