필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by