using ode45 with input arrays
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Richard Brown
le 28 Juin 2012
Modifié(e) : Richard Brown
le 28 Juin 2012
Please format your code by selecting it and using the Code button.
(thanks Walter)
Jan
le 28 Juin 2012
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?
Réponses (1)
Richard Brown
le 28 Juin 2012
Modifié(e) : Richard Brown
le 28 Juin 2012
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 commentaires
Voir également
Catégories
En savoir plus sur Function Creation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!