Having error 'Invalid array indexing'. Please help me to solve this issue
Afficher commentaires plus anciens
% Solve using Euler method
for i = 1:num_steps
v1_euler(i+1) = v1_euler(i) + dt * f(t(i), v1_euler(i), v2_euler(i))(1);
v2_euler(i+1) = v2_euler(i) + dt * f(t(i), v1_euler(i), v2_euler(i))(2);
Réponses (1)
Image Analyst
le 23 Juin 2023
What is f? If f is a function you can't do this:
f(t(i), v1_euler(i), v2_euler(i))(1)
You'd need to get the results (returned vector) from f, then do f(1)
for example
result = f(t(i), v1_euler(i), v2_euler(i)); % Get result vector out of "f" function.
v1_euler(i+1) = v1_euler(i) + dt *result(1);
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!