answersLogoWhite

0


Best Answer

% Definitions

R2D = 180/pi; % rad to deg

D2R = pi/180; % deg to rad

F2M = 0.3040; % feet to meter

m = 45.46; % kg

g = -9.8; % gravity (m/s^2)

j = sqrt(-1);

dt = 0.001; %1000Hz

R1 = 15*F2M; %m

R2 = 15*F2M;

% Initial conditions

xBall = [0; 0]; % theta/omega

% Machine initial conditions

Torque = (-1)*m*g*R1; % N-m

Pmotor = 1119000; % W

Tbreak = (4404 / 0.738)*2.3; % break torque in N-m

% Ball

I = m*(R1^2);

for launch=0:1:20

times_launched = launch + 1;

% Main loop

iter = 0;

for time=0:dt:1

% Index

iter = iter + 1;

% Torque generation and check

if( (xBall(2,1)) < ((Pmotor)/Tbreak) )

Torque = Tbreak;

else

Torque = (Pmotor)/xBall(2,1);

end

% From 0 degrees to 90 degrees

if ((xBall(1,1)*R2D) >= 0 ) ((xBall(1,1)*R2D) < 90)

% Calculate net torque

Tgrav = ( m*g*cos(xBall(1,1)))*R1;

Tnet = Torque + Tgrav;

% Calculate instantaneous angular acceleration

alphaB = Tnet/I;

% Calculate the derivative of the state

xdot = [ xBall(2,1); alphaB ];

% Integration of the state

xBall = xBall + xdot*dt;

% Dependent states

pBall = R1*( cos(xBall(1,1)) + j*sin(xBall(1,1)) );

vBall = xBall(2,1) * R1;

Power = (Tnet/R1) * vBall;

elseif ( ((xBall(1,1)*R2D) >= 90) ((xBall(1,1)*R2D) <= 180) )

% Calculate net torque

Tgrav = ( m*g*cos( xBall(1,1)) )*R1;

Tnet = Torque + Tgrav;

% Calculate instantaneous angular acceleration

alphaB = Tnet/I;

% Calculate the derivative of the state

xdot = [ xBall(2,1); alphaB ];

% Integration of the state

xBall = xBall + xdot*dt;

% Dependent states

pBall = real(vBall) * time;

Power = (Tnet/R1) * vBall;

end;

DATA(iter,:) = [ iter time xBall' alphaB Tnet xBall(1,1)*R2D ...

real(pBall) imag(pBall) real(vBall) imag(vBall) vBall Power ];

end;

end;

%% Trajectory of Projectile (y vs. x)

figure(1);

plot( DATA(:,8), DATA(:,9), '.' );

title ('Trajectory (y vs. x) of projectile during launch')

xlabel('x')

ylabel('y')

%% Range (x) vs. time

figure(2);

subplot (211), plot(DATA(:,2), DATA(:,8), '.' );

title ('Range(x) as a function of time')

ylabel('Range(x)')

%% Altitude (y) vs. time

subplot (212), plot(DATA(:,2), DATA(:,9), '.' );

title ('Altitude(y) as a function of time')

xlabel('time')

ylabel('Altitude(y)')

%% Velocity (x and y components) vs. time

figure(3);

subplot (211), plot(DATA(:,2), DATA(:,10), '.' );

title ('Velocity (x and y) as a function of time')

ylabel('Velocity(x)')

subplot (212), plot(DATA(:,2), DATA(:,11), '.' );

xlabel('time')

ylabel('Velocity(y)')

%% Velocity (total) vs. time

figure(4);

plot(DATA(:,2), DATA(:,12), '.' );

title ('Velocity(total) as a function of time')

xlabel('time')

ylabel('Velocity (total))')

%% Power vs. time

figure(5);

plot(DATA(:,2), DATA(:,13), '.' );

title ('Power as a function of time')

xlabel('time')

ylabel('Power')

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create a catapult simulation using matlab GUI?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you make graph from an equation in Matlab?

Initially, the equation can be directly realized using Matlab source code. Then various inputs can be applied to it. These values can easily be plotted on a graph using plot or stem command in Matlab.


How do you implement awgn in MATLAB without using awgn function?

no way... use awgn function in matlab


What has the author John G Proakis written?

John G. Proakis has written: 'Introduction to digital signal processing' -- subject(s): Signal processing, Digital techniques 'Digital signal processing' 'Contemporary communication systems using MATLAB and Simulink' -- subject(s): Computer simulation, Data transmission systems, MATLAB, Telecommunication systems


What is a sentence using the word catapult?

You use a catapult to launch things into the air.


How do you call matlab from java?

You can MATLAB from Java by using the matlabcontrol library available at link1. A walkthrough to get you started can be found at link2


Convolution in matlab using for loop?

There are a lot of convolution functions in matlab, mostly in the signal processing toolbox, so it depends on what you want to do. Matlab has extensive help files available online.


How do you modulate in matlab without using matlab tools?

You would have to write your own code for a modulation (Matlab has a convolution function not in the tools), otherwise you can use its built in function in the signal processing toolbox.


How do you convert sequence of images to video in matlab?

You can do this by selecting the sequence of images you want to animate and then using the Matlab's function called "im2frame". This will result in a video.


How do you determine determinant of matrix using matlab?

d = det(x);


What types of materials do you think you'll be using for the different parts of your catapult?

I think ill be using the different materials provided to me for different parts of the catapult that i am building/ creating.


What has the author Bahram Shahian written?

Bahram Shahian has written: 'Control system design using Matlab' -- subject(s): Automatic control, MATLAB, System design


When three dice are rolled what is the probability that at least two of the dice have the same value using Matlab?

The probability is 1 and you do not need Matlab to get that answer - only a little bit of thought.