Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Homework Help
Introductory Physics Homework Help
Shooting Arrows - Nonlinear Spring Problem
Reply to thread
Message
[QUOTE="TheBlenderer, post: 4543678, member: 491365"] [b]Yay, it worked![/b] I implemented the Leapfrog algorithm, and it worked! At first I got a sine wave (which isn't strange seeing as I basically modeled a spring), so I made the calculation stop as soon as x became positive. A bit of a hack solution, also because the rest of the vectors are zeros after that (that explains the sudden straight line in the graphs), but I didn't feel like polishing the code. I also used the erroneous value of -0.62 for x_initial, as it didn't really matter for this implementation (but thanks for checking anyways!) Here's my code: [CODE] %% Now attempting a Leapfrog integration dt=0.001; t=0:dt:0.013; x_in=-0.620; x_t=zeros(1,length(t)); v_t=zeros(1,length(t)); a_t=zeros(1,length(t)); x_t(1)=x_in; v_t(1)=0; a_t(1)=(-k1.*x_in-k2.*x_in.*exp(c.*x_in.^2))/m; i=2; while x_t(i-1)<0 x_t(i)=x_t(i-1)+v_t(i-1)*dt+0.5*a_t(i-1)*dt^2; a_t(i)=(-k1*x_t(i)-k2*x_t(i).*exp(c*x_t(i).^2))/m; v_t(i)=v_t(i-1)+0.5*(a_t(i-1)+a_t(i)).*dt; i=i+1; end hold all subplot(2,2,1), plot(t,v_t,'b'), title('Velocity with respect to time') subplot(2,2,2), plot(t,x_t,'r'), title('Distance with respect to time') subplot(2,2,3), plot(t,a_t,'g'), title('Acceleration with respect to time') [/CODE] And my graphs are attached. Cheers gneill :) [/QUOTE]
Insert quotes…
Post reply
Forums
Homework Help
Introductory Physics Homework Help
Shooting Arrows - Nonlinear Spring Problem
Back
Top