MATLAB Answers

0

No curve in plot when executing function with multiple data sets

Max Kennedy Till さんによって質問されました 2019 年 9 月 30 日
最新アクティビティ Jyotsna Talluri さんによって 回答されました 2019 年 10 月 3 日
So I have a function to output a value of heat capacity for a given species and temperature.
function[c]=HeatCapacity(Species,T)
if Species == 1
a = 38.91; b = 3.903e-2; c = -3.105e-5; d = 8.606e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
if Species == 2
a = 48.50; b = 9.188e-2; c = -8.540e-5; d = 32.40e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
if Species == 3
a = 29.10; b = 1.158e-2; c = -0.607e-5; d = 1.311e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
if Species == 4
a = 29.00; b = 0.2199e-2; c = -0.5723e-5; d = -2.871e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
% Cp = a + b*T + c*T^2 + d*T^3
And so I want to write a script that plots dependencies of heat capacity for all four species versus temperature in the temperature range ‐100ºC <= T <= 1000ºC in a single plot
for Species = 1:4
T = -100:1:1000
HeatCapacity(Species,T);
plot(T,HeatCapacity(Species,T))
xlim([-100,1000])
ylim([0,100])
end
However this returns a blank plot with no curves. How can I fix this in order to display the four curves?

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

回答者: Jyotsna Talluri 2019 年 10 月 3 日

The function output variable should be initialized same as the passing variable . For plotting multiple plots on the same curve use hold on and hold off
function Capacity = HeatCapacity(Species,T)
if Species == 1
a = 38.91; b = 3.903e-2; c = -3.105e-5; d = 8.606e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
if Species == 2
a = 48.50; b = 9.188e-2; c = -8.540e-5; d = 32.40e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
if Species == 3
a = 29.10; b = 1.158e-2; c = -0.607e-5; d = 1.311e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
if Species == 4
a = 29.00; b = 0.2199e-2; c = -0.5723e-5; d = -2.871e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
end
figure();
hold on;
for Species = 1:4
T = -100:1:1000
c=HeatCapacity(Species,T);
plot(T,c)
xlim([-100,1000])
ylim([0,100])
end
hold off

  0 件のコメント

サインイン to comment.



Translated by