Error using the solve command

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

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.
Tw2(1) and Tw1(1) are values from two separate 1x3072 matrices. I see what your saying now. I want Tw2[1] because I'm referencing a value.

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 11 Jun 2013
Edited: Alan Weiss on 11 Jun 2013
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.
In MuPAD, you can use the numeric::fsolve function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

6 Comments

Looking at the fsolve function, it seems to operate along the same way as the solve command, however it is a numeric solution if I am understanding correctly???
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.
I'll look into it when I get onto my school computer here in the morning. I completely understand that this might be a case where a numerical method must be used. One of my partners set it up using a numerical method, however it is sloppy and tends to be diverging. This seemed like a much cleaner simpler approach I figured I'd try. I'll keep you guys posted here in the morning.
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.
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.
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.

Sign in to comment.

Asked:

on 11 Jun 2013

Community Treasure Hunt

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

Start Hunting!