CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2012
    Posts
    1

    Matlab projectile motion HELP!

    Hey guys i was wondering if any of you could help, I'm trying to do a projectile motion simulation where the air resistance proportional to the square of the speed of the projectile. I'm having some serious troubles and was wondering if anyone could help! I will Genuinely pay someone if they help me alot. Thanks

    Heres my code for the motion without air resistance
    function projectilemotionwithairresistance()

    Vx=input('Enter the Horizontal Velocity Component ');
    Vy=input('Enter the vertical velocity component ');
    % Gets Values for the horizontal and vertical components of the velocity




    ind=1;
    t=[];
    t(ind)=0;
    x=[];
    y=[];
    x(ind)=0;
    y(ind)=0;
    dt=.01; %Increment of index
    g=9.8; % m/s^2
    % Test whether ball has hit the ground
    % ****x and y position****


    while ((y(ind)>0)|(ind==1))
    ind=ind+1;
    t(ind)=t(ind-1)+dt;
    x(ind)=Vx*t(ind);
    y(ind)=Vy*t(ind) - .5*g*(t(ind))^2;
    end
    % Plot Path of Ball
    plot(x,y)
    title('Path Of Projectile With No Air Resistance')
    %axis([0,400,0,80])
    xlabel('Distance (Metres)')
    ylabel('Height (Metres)')
    % Display the max height and distance
    fprintf('Max Distance = %-5.1f m\n',max(x));
    fprintf('Max Height = %-5.1f m\n',max(y));

  2. #2
    Join Date
    May 2012
    Posts
    4

    Re: Matlab projectile motion HELP!

    By now you must have figured this out, but...

    It looks like you have your solution trajectory has already been plotted for you in functional form. An analytical solution has already been found? Much simpler than solving an ODE.

    I've rewritten part of your code without checking to see if it works. It's up to you to debug it. Here's the general idea behind how movies can be made:

    /loop
    (1) A static image is created (plot does this for you)
    (2) Image is sent to screen
    /endloop

    All that you need to do is make multiple plots that show different snapshots of time. Can you graph a snapshot of 'time == 0'? Can you graph a snapshot of 'time == 1'? Good! Half of your work is done. Now all that you need to do is graph over a dozen more and send them to the screen!

    How are we doing this in matlab? Well, your while loop is a decent excuse to try this. All that you're doing in the altered code below is creating an image at 'time ==0', waiting for a small amount of time and creating another image at 'time == dt' (dt is the change in time). It does this until the ball reaches the ground.

    You'll need to calibrate the number in pause(#) to make matlab wait the amount of time you want it to.

    Check the condition in your while loop; I think 'while ((y(ind)>0)|(ind==1))' may need to be changed to: 'while ((y(ind)>0)||(ind==1))'

    Please don't offer to pay people to do your homework... that won't help you. What you are learning to do is powerful. It can make YOU lots of money if you master it and apply it. Just ask Pixar! Try to understand it. You're more than intelligent enough to figure this out. Spend more time swearing at matlab, and you'll get it!

    Also... you can find solution programs like this all over the internet, have you been looking?




    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Vx=input('Enter the Horizontal Velocity Component ');
    Vy=input('Enter the vertical velocity component ');
    % Gets Values for the horizontal and vertical components of the velocity




    ind=1;

    t=[];
    t(ind)=0;

    x=[];
    y=[];
    x(ind)=0;
    y(ind)=0;
    dt=.01; %Increment of index
    g=9.8; % m/s^2
    % Test whether ball has hit the ground
    % ****x and y position****
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    while ((y(ind)>0)|(ind==1))
    ind=ind+1;
    t(ind)=t(ind-1)+dt;
    x(ind)=Vx*t(ind);
    y(ind)=Vy*t(ind) - .5*g*(t(ind))^2;
    plot(x,y)
    title('Path Of Projectile With No Air Resistance')
    pause(0.2)
    end


    % Plot Path of Ball


    %axis([0,400,0,80])
    xlabel('Distance (Metres)')
    ylabel('Height (Metres)')

    % Display the max height and distance
    fprintf('Max Distance = %-5.1f m\n',max(x));
    fprintf('Max Height = %-5.1f m\n',max(y));
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured