Having error 'Invalid array indexing'. Please help me to solve this issue
Show older comments
% 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);
Answers (1)
Image Analyst
on 23 Jun 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);
Categories
Find more on Programming 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!