필터 지우기
필터 지우기

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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by