extra variables

I have an equation I am working with where I am altering the equation to solve for certain variables within the equation. I have used the syms function in the past and have never had a problem with it until today. I set up my equation and then ask it to solve for a certain variable. When it spits out the new equation Matlab has added two new variables to the mix. I've tried it 4 or 5 different ways and it continues to do the same thing. Does anyone know what is going on or why that is happening?

7 Comments

Sean de Wolski
Sean de Wolski on 12 Jul 2011
Show us the code!!
If we can't see what you're doing we can't help effectively.
Jason
Jason on 12 Jul 2011
EDU>> P0=(((1-g)/2)*(-cd*.6847*a*(((r*T)^.5)/V)*P1^k*t)+P1^k)^((2*g)/(1-g))
P0 =
1/(1/P1^((g - 1)/(2*g)) + (6847*a*cd*t*(T*r)^(1/2)*(g/2 - 1/2))/(10000*P1^((g - 1)/(2*g))*V))^((2*g)/(g - 1))
EDU>> isen ='P0=(((1-g)/2)*(-cd*.6847*a*(((r*T)^.5)/V)*P1^k*t)+P1^k)^((2*g)/(1-g))'
isen =
P0=(((1-g)/2)*(-cd*.6847*a*(((r*T)^.5)/V)*P1^k*t)+P1^k)^((2*g)/(1-g))
EDU>> solve(isen,'T')
ans =
(2.1330416924969127954324069056884*V^2*(1.0*P1^k - exp((3.1415926535897932384626433832795*l*(g - 1.0)*i)/g)/P0^((0.5*(g - 1.0))/g))^2)/(P1^(2.0*k)*a^2*cd^2*r*t^2*(0.5*g - 0.5)^2)
It may be difficult to see what I am talking about because its so jumbled up. I've used several different variables in the different runs but in this case and "i" and "l" appear, the variables change each time. I can do it by hand so its not the end of the world I was just trying to save some time. Now I'm just curious as to why its adding variables with no way to identify what those variables represent.
Sean de Wolski
Sean de Wolski on 12 Jul 2011
Do you have leftover variables from a previous run?
add:
clearvars
to the beginning of the file and see if it works.
Oleg Komarov
Oleg Komarov on 12 Jul 2011
Please edit your post formatting the code: http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question
Jason
Jason on 12 Jul 2011
if it helps this is the equation for pressure in an isentropic process. Now I want to solve for the temperature(T).
Jason
Jason on 12 Jul 2011
My apologies, there isnt much more editing I can do than this. I'll try the clear variables and try it again, I'll let you know what happens.
P0=(((1-g)/2)*(-cd*.6847*a*(((r*T)^.5)/V)*P1^k*t)+P1^k)^((2*g)/(1-g))
isen ='P0=(((1-g)/2)*(-cd*.6847*a*(((r*T)^.5)/V)*P1^k*t)+P1^k)^((2*g)/(1-g))'
solve(isen,'T')
ans =
(2.1330416924969127954324069056884*V^2*(1.0*P1^k - exp((3.1415926535897932384626433832795*l*(g - 1.0)*i)/g)/P0^((0.5*(g - 1.0))/g))^2)/(P1^(2.0*k)*a^2*cd^2*r*t^2*(0.5*g - 0.5)^2)
Jason
Jason on 12 Jul 2011
Sean, I cleared the variables but I am still getting the same thing. I'll do it by hand but I just wanted to know if anyone had seen this before and what it might be doing. I forgot to include this:
syms P0 g cd a r T V P1 t k
These are my original variables.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 12 Jul 2011

0 votes

i or I represent the square root of negative 1. "i" is used at the MATLAB level, and "I" is used in symbolic forms.

2 Comments

Jason
Jason on 12 Jul 2011
Okay, this may be a dumb question, why do both appear if they represent the same thing. The first few times I ran the equation I didn't use k as one of my variables but k popped up in the answer, does k stand for something similar?
Walter Roberson
Walter Roberson on 13 Jul 2011
Was it in the context of a RootOf() ? RootOf() introduces a dummy variable.

Sign in to comment.

Kai Gehrs
Kai Gehrs on 13 Jul 2011
Hi Jason,
two things come to my mind which could be helpful.
First: defining P0 and afterwards using it in a character string, will not trigger any evaluation. A simple example is a = 2 and then using the input 'x^2 = a' as an equation for 'solve'. The value for 'a' will not be plugged into the equation. You would need to use something like ['x^2 = ' char(a)] to build the equation. The char command should trigger the evaluation.
Second: the solver uses new variables to parameterize solutions. E.g. something like k*pi as the solution of 'sin(x) = 0'. In the current version of the Symbolic Math Toolbox you will get a warning that the solutions are parameterized and it tells you something about which sets are used for that (e.g. the integers, the reals, certain intervals etc.).
As a workaround, you could try to use the 'evalin(symengine,cmd)' command, where cmd is a character string with a MuPAD command:
evalin(symengine,'solve(P0=(((1-g)/2)*(-cd*.6847*a*(((r*T)^.5)/V)*P1^k*t)+P1^k)^((2*g)/(1-g)),T)')
Hope this helps a bit,
-- Kai

Asked:

on 12 Jul 2011

Community Treasure Hunt

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

Start Hunting!