Hi!(adsbygoogle = window.adsbygoogle || []).push({});

I have a question about an assignment.

It is about throwing a rock which should land 20 meters away from the "shooter". My job is to find the angle "a" which makes the rock land 20 meters away.

The motion is given by a multivariable, second order differential equation which I have already "converted" into a first order differential equation. I am only allowed to use the Runge-Kutta-method, and not allowed to use ODE45.

I have managed to write a code which works fine, but I need help with making a loop of some sort, in order to find a precise angle, a, which makes the rock land 20 meters away from the shooter.

I know that the angle should be approximately 1 radian.

Here is the code:

Code (Text):clear all

close all

clc

format long

%g = 9.81;

a = pi/4;

a = 1;

x0 = [0;1.5];

xPrim0 = 19.*[cos(a);sin(a)];

K = [0.02 0; 0 0.065];

f = [0; -9.81];

x = []; % Vi ska rÃ¤kna ut X (positionen), men vad skickar vi till funktionen?

xPrim = 19.*[cos(a);sin(a)]; % Ska det multipliceras med 19?

% xPrim Ã¤r vÃ¤l inte en funktion av vinkeln

% efter kastet?

h = 0.3;

T = 100;

hojd = 1.5;

%Q = [0.1 1 1.5 3.1];

%c0 = [0.1;0];

u = [x0; xPrim0];

u0 = [x0;xPrim0];

%F = [xPrim; f - norm(xPrim).*K*xPrim];

W = [];

% for i = 1:4

% u0 = [u(i);0];

u = u0;

U = u;

tt = 0:9;

for t=tt(1:end-1)

k1 = Fproj(u);

k2 = Fproj(u+0.5*h*k1);

k3 = Fproj((u+0.5*h*k2));

k4 = Fproj((u+k3*h));

u = u + (1/6)*(k1+2*k2+2*k3+k4)*h;

U = [U u];

end

% W = [W U];

plot(U(1,1:end),U(2,1:end))

hold on

line([0 25], [0 0])

line([20 20], [-5 5])

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab: Finding the right angle

Tags:

Loading...

Similar Threads - Matlab Finding right | Date |
---|---|

Python How can I run Python by getting values from Matlab | Mar 7, 2018 |

What is each step of this Matlab program doing? | Feb 21, 2018 |

C/++/# Help with MATLAB code? | Feb 9, 2018 |

How to find phase values at neighboring pixel in an image? | Apr 30, 2015 |

MATLAB find function 4D array | Jun 23, 2009 |

**Physics Forums - The Fusion of Science and Community**