From: Dan Thatcher on 25 Jun 2010 06:32 Hi everyone, I am trying to build a model of a car accelerating from standstill over a 0.5 seconds time duration in millisecond intervals. For now I am only concerned with the angular displacement, angular velocity and angular acceleration of the body. I have a working model in Excel and am now trying to do the same in Matlab, with little success! The equations used are the simple equations of motion: θ=(ω1)t+0.5*α(t^2) ω2=ω1+αt α=T/I Sprung Moment (Ms)=2θ((kwf x L12)+(kwr x L22)) Damping Moment (Md)=2θ((Cwf x L12)+(Cwr x L22)) Nett Applied Moment=Total Overturning Moment of the body– Ms – Md where, Overturning moment=Sprung mass*acceleration*CofG height (assumed constant) Kwf=Front spring rate Kwr=Rear spring rate Cwf and Cwr=Front and Rear damping rates. But for the 1st millisecond all the equations must be processed to form a reference for the next millisecond and so on: %Initial Conditions s=0; %angular displacement v=0; %angular velocity acc=Mo/I; %angular acceleration Md=0; %Damping moment Ms=0; %Sprung moment Mn=Mo; %Nett moment t=0.001; %time interval for i=0:0.001:0.5 s(i+1)=(v(i)*(t))+(0.5*acc(i)*(t)^2); st(i+1)=cumsum(s(i)); v(i+1)=v(i)+(acc(i)*t); Md(i+1)=2*((Cf*x^2)+(Cr*x1^2))*v(i); Ms(i+1)=2*((kf*x^2)+(kr*x1^2))*st(i); Mn(i+1)=Mo-Md(i+1)-Ms(i+1); acc(i+1)=I/Mn(i+1); end I am aware that there will be some basic errors with this as I am still very much a beginner with Matlab, to be honest I'm not even sure if using a for loop is the right way to approach this. The model runs if 'i=1:1:500' but the results are wrong. I hope this is clear and any help would be much appreciated.
From: us on 25 Jun 2010 07:10 "Dan Thatcher" > for i=0:0.001:0.5 > s(i+1)=(v(i)*(t))+(0.5*acc(i)*(t)^2); > end > > I am aware that there will be some basic errors with this as I am still very much a beginner with Matlab, to be honest I'm not even sure if using a for loop is the right way to approach this. The model runs if 'i=1:1:500' but the results are wrong. > > I hope this is clear and any help would be much appreciated. well... a typical unhealthy mix of a timing var (your loop indexer) and an index var... a hint: - consider something like this and rewrite your loop accordingly tvec=0:.1:1; nt=numel(tvec); s=zeros(1,nt); s(1)=1; for i=2:nt % <- loop index s(i)=tvec(i).*s(i-1); % <- a stupid example to show the various elements... end us
|
Pages: 1 Prev: problem with plotting differential equation Next: LDA ouput as classes seperated well in plot |