====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gibson:teaching:fall-2013:math445:lab11 [2013/12/05 08:56] szeto |
gibson:teaching:fall-2013:math445:lab11 [2013/12/05 09:10] (current) szeto |
||
---|---|---|---|
Line 50: | Line 50: | ||
[t,x]= ode45(f,[0:0.1:200] ,[ 0,0,v0*cos(theta), v0*sin(theta) ); | [t,x]= ode45(f,[0:0.1:200] ,[ 0,0,v0*cos(theta), v0*sin(theta) ); | ||
+ | |||
xdistance = interp1(x(50:end,2), x(50:end,1), 0); % This is how you can compute ''xdistance'' | xdistance = interp1(x(50:end,2), x(50:end,1), 0); % This is how you can compute ''xdistance'' | ||
% accurately from an ''x,y'' trajectory using interpolation. | % accurately from an ''x,y'' trajectory using interpolation. | ||
% It will return the value of $x$ for which $y=0$, i.e. | % It will return the value of $x$ for which $y=0$, i.e. | ||
% where the cannonball hits the ground. | % where the cannonball hits the ground. | ||
+ | |||
end | end | ||
</code> | </code> | ||
Line 66: | Line 68: | ||
- | If your xdistance is a NaN, you may have to increase the time span that you're running ode45 on. | + | If your xdistance is a NaN, you may have to increase the number 50 in the interp1 function (1000 might be good, that is roughly half the length of [0:0.1:200]). |
| |