"Error using plot, A numeric or double convertible argument is expected" Having vector issues with my symbols and I don't know why!

1 Ansicht (letzte 30 Tage)
Nlayers=20; %number of layers in the lung
syms z;
subs(z, input('Enter layer number')); % specific layer
TLC=7; %total lung capacity
Htot=0.16; %total lung height, metres
plung=300; %lung density kg/m3
Vad=0.15; %Volume of the anatomical dead space
g=9.81; %Gravitational acceleration
Hz=(Htot/Nlayers)*(z); %height of each layer
Nalvtot=300; %total number of alveoli
Nalvz=Nalvtot/Nlayers; %Number of alveoli in a layer
Valvmax=(TLC-Vad)/Nalvtot; %maximum volume
syms r;
Valvz=(4/3)*pi*r^3; %volume of the alveolus in layer z
Pe=(0.42-log(1/((0.98*Valvz/Valvmax)+0.015)-1)*0.22); %Elastic pressure
y=15*10^-3; %surface tension
Vtotal=Vad+symsum(Nalvz*Valvz, z, 0, 20);
Py=(2*y)/r; %Pressure due to surface tension
Ventilator_pressure;
Phydroz=plung*g*Hz; %Hydrostatic gradient at a given lung height
Pcw=0.71-log((0.95*TLC)/((Vtotal/TLC)-(0.22*TLC))-1)*0.58; %Pressure component of the chest wall
[r, z] = solve(Py+Pe == Pvent-Phydroz-Pcw);
figure;
ezplot(r);
This is my code, but when i run it, it says there's an error, i think its because its making hte symbols into vectors which aren't equal in size, but im not sure why its doing that! Help!
  2 Kommentare
David Young
David Young am 27 Mär. 2015
I wonder why you are using the symbolic toolbox. Is there a reason for z and r to be syms? Could you try doing it as an ordinary numerical computation (i.e. no syms)?
sophie webster
sophie webster am 27 Mär. 2015
not particularly, it was suggested that i do so, I just want to be able to construct a number of graphs using all of the variables above. How would i need edit it to removes the syms other than those statements?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 27 Mär. 2015
If you want to keep your code symbolic, see if the ezplot function will work.
  5 Kommentare
Walter Roberson
Walter Roberson am 4 Mai 2016
You have no made any connection between the t of the equation and the t1 of the locations to plot at
plot(t1, subs(dv1, t, t1))
Stephane Magnam
Stephane Magnam am 4 Mai 2016
So I have a set of 3 equations for velocity in function of time. Each of them is associated with a range of time 't'. I am trying to plot on separate graphs the acceleration and the second derivative of the velocity. That's why I have this confusion about t and t1, t2, and t3. Here are the info:
dt=0.5;
t=[0:dt:50];
v1=11*t^2-5*t;
v2=1100-5*t;
v3=50*t-2*((t-20)^2);
dv1=diff(v1);
t1=[0:0.5:10];
figure(1);
plot(t1,subs(dv1, t, t1));
hold on;
dv2=diff(v2);
t2=[20:0.5:35];
plot(t2,subs(dv2, t, t2));
hold on;
dv3=diff(v3);
t3=[35:0.5:50];
plot(t3,subs(dv3, t, t3));
I realize that my code does not necessarily have a lot of sense, but it is just an intuitive way to approach the problem. t1, t2, t3, in the code are the ranges of t for equations v1, v2, and v3 respectively. Any easier way to approach this is appreciated? PS: Using subs made it work but it appears that the graph I obtain does not make a lot of sense since I'm getting 3 separate lines.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by