フィルターのクリア

Unable to perform assignment because the left and right sides have a different number of elements.

1 回表示 (過去 30 日間)
%euler exlicit method
h = 0.1;
x = 1:h:10;
y = [0 -1];
for i = 1:0.1:10
x(i+1)=h+x(i);
y(i+1) =y(i) + h * f(x(i), y(i));
disp(x(i+1));
disp(y(i+1));
end
figure(2)
plot(x,y);
hold on
function dy = f(x,y)
d=50;
x = 1:0.1:10;
c1=-1-d^2/(d^2+1);
dy=c1*exp(-d*x)+d*sin(x)/(d^2+1)+d^2*cos(x)/(d^2+1);
%analytical solution
figure (1)
plot(x,dy);
xlabel('x');ylabel('y(x)');title('Analytical Solution');grid on
hold on
end

採用された回答

KSSV
KSSV 2021 年 2 月 4 日
function myfunc()
%euler exlicit method
h = 0.1;
x = 1:h:10;
y = [0 -1];
for i = 1:length(x)
x(i+1)=h+x(i);
y(i+1) =y(i) + h * f(x(i), y(i));
disp(x(i+1));
disp(y(i+1));
end
figure(2)
plot(x,y);
hold on
end
function dy = f(x,y)
d=50;
% x = 1:0.1:10;
c1=-1-d^2/(d^2+1);
dy=c1*exp(-d*x)+d*sin(x)/(d^2+1)+d^2*cos(x)/(d^2+1);
%analytical solution
% figure (1)
% plot(x,dy);
% xlabel('x');ylabel('y(x)');title('Analytical Solution');grid on
% hold on
end

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by