using ode45 with input arrays

1 回表示 (過去 30 日間)
Clarisa Williams
Clarisa Williams 2012 年 6 月 27 日
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
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
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
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.

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by