- define the function with input arguments.
- call the function with input values.
Function with 3 input arguments
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Given: Write a function to calculate the position of a projectile at any given time, t. The function should have 3 input arguments arguments: the initial velocity v_0, the initial launch angle theta_0, and the time at which you want to know the position. The function should then return the vertical (y) position of the projectile at that time. Assume that we are working in metric units with with acceleration of gravity g=9.81 m/s^2. Call your function projAlt_username. Remember, if we are launching a projectile at an angle, only a portion of that velocity will actually be in the vertical direction! For now, lets assume that the angle will be provided in degrees and the initial launch altitude (y_0) is zero.
v_y0=v_0*sin(theta_0)
y=y_0+v_y0*t-1/2*g*t^2
Find: Once we get this to work for a single value of time we can adjust the function to accept a vector of time values and return a vector of y values. Since we provided the vector of time values as an input argument, we now have everything needed in order to plot the altitude as a function of time.
Issue: I can't even get the code to run, I am just at a loss. Functions really throw me for a loop. (pun intended)
My Solution: I just know I am missing something fundamental here...
function y = projAlt_kweave19(v_0,theta_0,t)
% projAlt_kweave19 will return the vertical (y) position of the projectile at any given time t
% projAlt_kweave19 calculates the position of a projectile at any given
% time t with 3 input arguments: the initial velocity, V_0, the initial
% launch angle, theta_0, and the time at which you want to know the
% position. The function will then return the vertical (y) position of the
% projectile at the thtat time. Assume we are working in metric units with
% the acceleration of gravity g=9.81 m/s^2.
y_0=0
g=9.81
v_y0 = v_0*sin(theta_0);
y = y_0+v_y0*t-1/2*g*t^2;
end
I am using this line to call my function: v_0=100; theta_0=45; t=5; projAlt_kweave19
0 Commenti
Risposta accettata
Stephen23
il 6 Mar 2024
Modificato: Stephen23
il 6 Mar 2024
"I just know I am missing something fundamental here..."
Exactly the same fundamental concept as your previous questions:
You defined a function with three input arguments, and then called it with zero inputs. How will that work?
A = 100;
B = 45;
C = 5;
D = projAlt_kweave19(A,B,C)
function y = projAlt_kweave19(v_0,theta_0,t)
% projAlt_kweave19 will return the vertical (y) position of the projectile at any given time t
% projAlt_kweave19 calculates the position of a projectile at any given
% time t with 3 input arguments: the initial velocity, V_0, the initial
% launch angle, theta_0, and the time at which you want to know the
% position. The function will then return the vertical (y) position of the
% projectile at the thtat time. Assume we are working in metric units with
% the acceleration of gravity g=9.81 m/s^2.
y_0=0;
g=9.81;
v_y0 = v_0*sin(theta_0);
y = y_0+v_y0*t-1/2*g*t^2;
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!