- define the function with input arguments.
- call the function with input values.
Function with 3 input arguments
조회 수: 22 (최근 30일)
이전 댓글 표시
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
채택된 답변
Stephen23
2024년 3월 6일
편집: Stephen23
2024년 3월 6일
"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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!