using ode45 with input arrays
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to use ode45 but I have three arrays and can't get it to work.
Here is my function:
function [ ydot] = integration( t )
%This function will integrate
theta=[2.05320782261561,2.05350842309907, etc. it is a 1x753 array gamma=[0.0919239472479973,0.0916551270720756,et. It is also a 1x753 array velocity=[157;165.432396880000;189.834767478843; etc. It is a 754x1 array
y(1)= velocity*cos(gamma)*cos(theta)
y(2)= velocity*sin(gamma)*sin(theta)
y(3)= velocity*sin(gamma)
end
Here is my script program:
tspan=[0 753];
yo=[0.710174472636493,4.98858733451279, 0]
[t,y]=ode45(@integration, tspan,yo)
size(t)
I tried this for if theta, gamma, and velocity equal a single number and it worked but I cannot get it to work in the array. I copied and pasted the arrays from .mat files, which I was given to work with.
2 件のコメント
Richard Brown
2012 年 6 月 28 日
編集済み: Richard Brown
2012 年 6 月 28 日
Please format your code by selecting it and using the Code button.
(thanks Walter)
Jan
2012 年 6 月 28 日
What does "can't get it to work" explicitly mean? Do you get an error message? If so, which one? Does Matlab moan, that you want to reply "ydot" but define "y" only?
回答 (1 件)
Richard Brown
2012 年 6 月 28 日
編集済み: Richard Brown
2012 年 6 月 28 日
OK, I understand what you're asking now
First make sure theta, gamma, and velocity are column vectors of the same length, and assuming the samples have unit spacing. Then
y = cumtrapz([velocity .* cos(gamma) .* cos(theta), ...
velocity .* sin(gamma) .* sin(theta), ...
velocity .* sin(theta)])
should do the trick. ode45 is not required as there is no dependence on y in your rhs.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!