help with function loop

So I'm having trouble with the loop portion of my function. when I try multiplying my v(n) by t I get an error that's there's a different number of elements on either side of my function. I don't quite see what I need to fix. Any help would be appreciated, thanks.
function [v,x,t,FD] = EDDO(N,dt,wd,k,b,f,F,m,x0,v0,t0)
x=zeros(N,1); % Preallocate position array
v=zeros(N,1); % Preallocate velocity array
t=zeros(N,1); % Preallocate time array
FD=zeros(N,1); % Preallocate array for driving force values
x(1)=x0; % Set initial condition for position in m
v(1)=v0; % Set initial condition for velocity in m/s
t(1)=t0; % Set initial time in s.
FD(1)=F*cos(wd*t(1)); % Calculate initial force value
for n=1:N % Set the number of loops
v(n+1)=v(n); % calculate next velocity
x(n+1)=x(n)+v(n); % calculate next position
t(n+1)=t(n); % calculate next time value
FD(n+1)=FD(n); % calculate next driving force value
end
end

1 个评论

I do not see any multiplication other than the initial force value ?
What are size(F), size(wd) ?
t(n+1)=t(n); % calculate next time value
That is likely to be wrong. Next time value would be at a later time: time should be increasing.
FD(n+1)=FD(n); % calculate next driving force value
Maybe. But I would tend to suspect that the driving force is intended to change as time changes, F*cos(wd*t(n)) or F*cos(wd*t(n+1)) or perhaps the mean of those two.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by