Why can't I run my code
이전 댓글 표시
function novo_y = integrador_euler(f, y, x, h)
novo_y = y + f(y,x)*h;
end
xmax = 2.5; % valor máximo de x
h= 0.01; % passo de integração
x = 0; % valor inicial de x
y= [3, 0.2]; % valores inicias de y e y'
lista_x = [x]; lista_y = [y(1)]; % listas com valores de x e y
while x < xmax % ciclo sobre o espaço
x = x + h; % avança um passo em x
y = integrador_euler(@EqDif_Canon, y, x, h); % valor de y no novo ponto ( método de Euler)
lista_x = [lista_x x]; lista_y = [lista_y y(1)]; % adiciona os valores às listas
end
plot(lista_x, lista_y); % gráfico y vs x
title(' Evolução de y ');
xlabel('x'); ylabel('y(x)'); % nome dos eixos
xlim([0 2.5]); % limites do eixo dos x
fprintf('O valor de y(2.5) é %f\n', lista_y(end)) % apresenta o ultimo valor da lista y
답변 (1개)
Stephen23
2022년 2월 17일
0 개 추천
Move the function to the end of the script. The function(s) must come after all other code:
카테고리
도움말 센터 및 File Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!