Having error 'Invalid array indexing'. Please help me to solve this issue
显示 更早的评论
% 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);
回答(1 个)
Image Analyst
2023-6-23
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);
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!