Clear Filters
Clear Filters

How to fix graph with for loop

3 views (last 30 days)
sophp
sophp on 31 Jan 2018
Commented: Star Strider on 31 Jan 2018
I am trying to plot a graph to show me the operating curve of \tau with Y_B for different values of T. This is the code below:
t = 1:2:20;
T = 600:10:850;
for i=1:numel(T)
k1(i) = 1e7 .* exp(-12700 ./ T(i));
k2(i) = 5e4 .* exp(-10800 ./ T(i));
k3(i) = 7e7 .* exp(-15000 ./ T(i));
Y_B = (k1(i).*t.*(k1(i)+k3(i)))./(((k2(i).*t)+1).*(k1(i)+k3(i)).*(1+(t.*(k1(i)+k3(i)))));
plot(t, Y_B);
xlabel('Residence time, \tau / s')
ylabel('Yield of Maleic Anhydride ')
end
The graph produced is incorrect as it only has one operating curve. What is wrong with my code?

Accepted Answer

Birdman
Birdman on 31 Jan 2018
Use hold on command:
t = 1:2:20;
T = 600:10:850;hold on;
for i=1:numel(T)
k1(i) = 1e7 .* exp(-12700 ./ T(i));
k2(i) = 5e4 .* exp(-10800 ./ T(i));
k3(i) = 7e7 .* exp(-15000 ./ T(i));
Y_B = (k1(i).*t.*(k1(i)+k3(i)))./(((k2(i).*t)+1).*(k1(i)+k3(i)).*(1+(t.*(k1(i)+k3(i)))));
plot(t, Y_B);
xlabel('Residence time, \tau / s')
ylabel('Yield of Maleic Anhydride ')
end

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!