- #1

- 13

- 0

## Homework Statement

Hi There!

MX''=Fn(sin θ - uCos θ )

MZ''=Fn(cos θ + uSin θ ) - Mg

Fn,M,θ,u is constant

fn/M = 0.866

M = 6000

θ = 30

u = 0.5774

i split my motion equation into 2 individual 1st ode,

X' = Vx

Z' = Vz

Vx'=[fn*(sin θ - uCos θ )]/M

Vz'={[fn(cos θ + uSin θ )]/M} - g

After trying many tutorials i still don't understand how to implement my motion equation into matlab,

i tried to do the following for Vz' motion but it seems wrong, my right hand side of the equation does not have t or y. please help !

clc; % Clears the screen

clear all;

h=0.1; % step size

thete=30;

g=9.81;

x = 0:h:3; % Calculates upto y(3)

y = zeros(1,length(x));

y(1) = 5; % initial condition

F_z = @(t,y) 0.866*(cos(thete)+0.5774*(sin(thete)))-g; % function

for i=1:(length(x)-1) % calculation loop

k_1 = F_z(x(i),y(i));

k_2 = F_z(x(i)+0.5*h,y(i)+0.5*h*k_1);

k_3 = F_z((x(i)+0.5*h),(y(i)+0.5*h*k_2));

k_4 = F_z((x(i)+h),(y(i)+k_3*h));

y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation

end

hold on %Plot graph

plot(x,y,'+-', 'Linewidth', 1.5, 'color', 'blue')

xlabel('x')

ylabel('y')

legend('RK4')

Thank you