Not all Subplots are plotting

17 ビュー (過去 30 日間)
Lilly
Lilly 2014 年 5 月 26 日
回答済み: Sara 2014 年 5 月 26 日
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

回答 (1 件)

Sara
Sara 2014 年 5 月 26 日
you have for j = 1:a with a = 0.1, i.e. it never enters the loop

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by