Error in simple ode45 functions
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, I am trying to solve a non-stiff 2nd order ODE with ode45 function. My ODE is d^2y/dt^2 = -g + (4/15)*(1/m)*(dy/dt)^2
Here is the ode function file that I made
function [ ode_fun_vect ] = ode_1_fun( t,z )
global m g
m=80;
g=9.81;
ode_fun_vec=[z(1);-g+(4/15)*(z(1))^2/m];
end
And here is script to solve ode:
clc;
clear all;
close all;
initial_cond=[600,0];
time_range=[0,20];
[t,y]=ode45(@ode_1_fun,time_range,initial_cond);
figure();
subplot(2,1,1);
plot(t,y(:,1));
xlabel('time');
ylabel('displacement');
subplot(2,1,2);
plot(t,y(:,2));
xlabel('time');
ylabel('velocity');
However I am getting some errors saying: Output argument "ode_fun_vect" (and maybe others) not assigned during call
Can someone help me? Thanks in advance!
0 件のコメント
採用された回答
Star Strider
2014 年 9 月 24 日
Typo!
You defined ‘ode_fun_vect’ as your function output and ‘ode_fun_vec’ as the value it calculates. Change one or the other and your ODE integrates successfully.
2 件のコメント
Star Strider
2014 年 9 月 24 日
My pleasure!
That’s the first problem I look for, since I have typos in my own code more often than I’d like to admit.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!