MATLAB error - "??? Undefined function or variable 'x'."
Show older comments
Hi! I'm just getting started on MATLAB, and I need to solve the following:
((P1/T1)*(((Q/Cp)+T1*((x/P1)^((n-1)/n)))/x))==(((1-E*(((P2/x)^(1/n))-1))/(1-E*(((x/P1)^(1/n))-1)))*(VbA/VbB)))
where 'x' is the variable. I've assigned the values for all the constants and tried using fsolve(func,var), but I keep getting an error message as follows:
??? Undefined function or variable 'x'.
I haven't been able to find where the mistake lies, so help would be very much appreciated!
Answers (2)
Walter Roberson
on 19 Jun 2011
If you have the symbolic toolbox, you would use
syms x
S = solve(((P1/T1)*(((Q/Cp)+T1*((x/P1)^((n-1)/n)))/x)) - (((1-E*(((P2/x)^(1/n))-1))/(1-E*(((x/P1)^(1/n))-1)))*(VbA/VbB)), x)
Note: you had an extra ")" at the very end.
Unfortunately if n is a positive integer, this will end up involving the roots of a polynomial of order (n^2) (e.g., a degree 25 polynomial for n=5).
If n is positive and rational, the solution can end up involving the roots of a fairly high order polynomial whose order is not obvious to me. For example, n=5/9 involves a degree 61 polynomial
6 Comments
Alejandra
on 19 Jun 2011
Walter Roberson
on 19 Jun 2011
Some values of n will lead to polynomials of even order. When that happens, there will always be an even number of real roots -- 0, 2, 4, 6, or as appropriate. If you used fsolve, you would end up with _one_ of the real roots, and it would not be controllable as to which one you got as fsolve() does not accept bounding constraints.
When polynomials of odd order are generated, there will be an odd number of real roots, including plausibly only a single real root -- but if there *are* multiple real roots, again fsolve() might give you any of them.
If you do have the symbolic toolbox, and you use solve(), and n is numeric and not symbolic, then you should in theory get out an expression involving roots of a polynomial. For any one value of n, you will be able to write that expression in terms of roots(), which would be able to calculate (approximations of) all of the roots given the numeric values of all of the parameters; you would then be able to filter the results as appropriate.
Walter Roberson
on 19 Jun 2011
What sort of values do you expect for n ?
Alejandra
on 19 Jun 2011
Walter Roberson
on 20 Jun 2011
Solving that with solve() might take quite a lot of time and memory. I was running n=314/100 (i.e., the first few digits of Pi) and after about 25 minutes Maple had gone through about 2 Gb of memory and I had to kill the program.
Walter Roberson
on 20 Jun 2011
Could you give some sample values for the other parameters?
Walter Roberson
on 19 Jun 2011
The fsolve() approach would be to use
fsolve(@(x) ((P1/T1)*(((Q/Cp)+T1*((x/P1)^((n-1)/n)))/x)) - (((1-E*(((P2/x)^(1/n))-1))/(1-E*(((x/P1)^(1/n))-1)))*(VbA/VbB)), x0)
where x0 is an initial guess. As I mentioned earlier, this will return a single root and you do not get any control over which one.
You could also use
fzero(@(x) ((P1/T1)*(((Q/Cp)+T1*((x/P1)^((n-1)/n)))/x)) - (((1-E*(((P2/x)^(1/n))-1))/(1-E*(((x/P1)^(1/n))-1)))*(VbA/VbB)), [x0,x1])
where x0 and x1 are starting values and you are sure that the expression will be of differing signs at the two points. This allows you to control the search interval but does require you have an idea of where the bounds are.
1 Comment
Alejandra
on 19 Jun 2011
Categories
Find more on Linear Algebra 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!