Why can't I run my code
Show older comments
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
Answers (1)
Stephen23
on 17 Feb 2022
0 votes
Move the function to the end of the script. The function(s) must come after all other code:
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!