euler's method, error, when I run the code i get an error message when trying to create the array for the x values, Array indices must be positive integers or logical values.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Callum Chalmers
le 25 Sep 2020
Réponse apportée : Alan Stevens
le 25 Sep 2020
clear
clc
close all
t0 = 0;
x0 = 3;
tf = 1;
n = 10;
tArray = linspace(t0, tf, n+1);
xArray = [x0];
h = (tf - t0)/n;
%--------------------------variables------------------------
%function for diffrential equation
f =@ (t,x) -3*t*x;
for ii = h : n
x = x0 + h * f(t0,x0);
t = (t0 + h);
x0 = x;
t0 = t;
xArray(ii+1) = x0
end
disp (xArray)
disp(tArray)
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Propagation and Channel Models dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!