Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
%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

Akzeptierte Antwort

KSSV
KSSV am 4 Feb. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by