No curve in plot when executing function with multiple data sets

4 ビュー (過去 30 日間)
Max Kennedy Till
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?

回答 (1 件)

Jyotsna Talluri
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

カテゴリ

Help Center および File ExchangeGraphics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by