Error regarding "unknown variable"

6 views (last 30 days)
Karina Reynolds
Karina Reynolds on 11 Feb 2016
Answered: Walter Roberson on 11 Feb 2016
I am trying to do an integration of the following problem: "Use MATLAB to write a script to determine work (w) during reversible isothermal expansion (T = 295K) from Vm(i) = 11.2 L/mol to Vm(f) = 33.6L/mol: (a) perfect gas"
When I type in the following code:
%int of p with respect to Vm ideal
clear
clc
syms R T Vm; %ideal gas
assume (T>0 Vm>0) %restrictions of T and Vm
p=R*T/Vm; %ideal gas law
f=in(p,Vm); %int of p wrt Vm
g=in(p,Vm,11.2,33.6); %int of p wrt Vm from 11.2L/mol to 33.6 L/mol
h=subs(g,[R,T],[0.0821,295]); %R=0.0821 atmL/Kmol T=295K
r=double(h); %final value
I am getting an error in the 5th line saying that Vm is an unknown variable. If i delete Vm I get the following error:
'integer', 'rational', 'real', 'positive'
The input did not match any of the valid strings.
Error in sym/in (line 11)
mset = setToMuPADSet(set);
Error in set3p1a (line 7)
f=in(p,Vm); %int of p wrt Vm
Caused by:
Error using validatestring>checkString (line 86)
Expected input to be one of these types:
char
Instead its type was sym.
I was how to correct this error and why matlab is not recognizing Vm as a variable even though i put it in the syms line.
  1 Comment
Guillaume
Guillaume on 11 Feb 2016
Rather than putting blank lines between each line of code. Just paste your code as is, then click on the {}Code button at the top of the edit box.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 11 Feb 2016
assume (T>0 & Vm>0) %restrictions of T and Vm
f = int(p,Vm); %int of p wrt Vm
You were using "in" rather than "int"

Community Treasure Hunt

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

Start Hunting!