MATLAB Answers

ML
0

How to print the intersection between two functions?

Asked by ML
on 12 Apr 2019
Latest activity Answered by darova
on 12 Apr 2019
Here is my code:
% Projectile motion
z0=0;h0=0; tmax=3; t=[0:0.1:1]*tmax;
pr_xdot = @(t,x) ([x(2); -9.81; x(4); 0]);
[tt,zz]=ode45(pr_xdot,t,[z0; v0z; h0; v0h]);
% Distance BC
x=0:0.1:15; y=x*tand(-beta);
plot(zz(:,3), zz(:,1), x, y); grid on; legend ('Projectile','Inclination');
xlabel('Horizontal distance [m]'); y1=ylabel('Vertical distance [m]');
interp1(x,y,pr_xdot)
I'm trying to use interp1 to find the value where the differential equation intersections with the simple x,y linear plot. I then want to print the resulting x and y coordinate. But I'm not having any luck with my interp1 function
Projectile.png

  0 Comments

Sign in to comment.

Tags

Products

1 Answer

Answer by darova
on 12 Apr 2019

zz1=interp1(zz(:,3),zz(:,1),x); % if you want to interpolate projectile
mm.png
mm1.png
mm2.png More points - better precision

  0 Comments

Sign in to comment.