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
Stephen23 2022 年 2 月 17 日

0 投票

Move the function to the end of the script. The function(s) must come after all other code:

カテゴリ

ヘルプ センター および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

質問済み:

2022 年 2 月 17 日

回答済み:

2022 年 2 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by