Not all Subplots are plotting

2 views (last 30 days)
Lilly
Lilly on 26 May 2014
Answered: Sara on 26 May 2014
This is my function: Only the last subplot is plotting. I have been passing in: hold on first(0, 10, 0.1, 4);
function first(start, finish, a, h)
%Declare initial values with respect to the function. x =start:h:finish; y = zeros(1, length(x)); y(1) = 1; n=1;
%To create as many subplots as there are increment values (and later, one more for the analytical solution): for j = 1:a
%Change h to change increment for each subplot.
if j>=2
h=h/10;
end
while x(n)<=finish
%while x value does not exceed the maximum x value
y(n+1) = y(n)+(-4 * (x(n).^3) * (y(n).^2))*h;
% x(n+1) = x(n) + h;
n = n+1;
end
print j
xlabel('x axis')
ylabel('y axis')
title('Graph')
subplot(5, 1, j); plot(x, y, '--')
end
%Now compare with analytical solutions: y(x) = 1/(x^4+1). subplot(5, 1, 5); x =start:0.1:finish; yaccurate = 1\(x.^4 +1); xlabel('x axis') ylabel('y axis') title('Analytical Solution') plot(x, yaccurate, 'g')
hold off

Answers (1)

Sara
Sara on 26 May 2014
you have for j = 1:a with a = 0.1, i.e. it never enters the loop

Tags

Community Treasure Hunt

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

Start Hunting!