Matlab
Objectives
Write a function that accepts variable number of arguments
Write a function that returns multiple arguments
Use fprintf (or sprintf) for formated output to the screen
Review physics of a projectile trajectory with no air resistance
Instructions
Write a Matlab function called work09.m that computes the maximum horizontal and vertical distance of a projectile and the total travel time, given the firing angle and initial velocity. Also, accept a third optional parameter that adjusts the gravitational constant (g = 9.8065 m2/s default). The angle input is degrees from horizontal, and velocity is m/s. You may need to consult a physics textbook or a reputable web resource such as https://en.wikipedia.org/wiki/Projectile_motion.
Your function must do the following:
Use nargin to determine whether there is an optional g parameter given
Calculate the correct vertical and horizontal distances, and total travel time
Have sufficiently detailed comments in the appropriate location in the function such that typing help work09 would completely describe how to use your function
Use appropriate formatting for output information to the screen
Sample Output (four possibilities shown)
>> work09(38,15); x_max = 22.3 m y_max = 4.35 m t_max = 1.9 sec
>> [xm, ym, tm] = work09(38,15) x_max = 22.3 m y_max = 4.35 m t_max = 1.9 sec
xm = 22.2621
ym = 4.3483
tm = 1.883
>> work09(38,15) x_max = 22.3 m y_max = 4.35 m t_max = 1.9 sec
ans = 22.2621
>> work09(38,15,9.0); x_max = 24.3 m y_max = 4.74 m t_max = 2.1 sec
function [x_max, y_max, t_max]= work09(angle,v0)
t = 0;
y = 0;
x = 0;
g = 9.802;
y_a = [];
t_a = [];
x_a = [];
y = v0*t*sin(angle)-0.5*g*t.^2;
x = v0*t*cos(angle);
y_a(end+1) = y;
while ge(y,0)
y = v0*t*sin(angle)-0.5*g*t.^2;
x = v0*t*cos(angle);
t = t + 0.1;
y_a(end+1) = y;
x_a(end+1) = x;
t_a(end+1) = t;
end
x_max = max(x_a);
y_max = max(y_a);
t_max = max(t_a);
end
Matlab Objectives Write a function that accepts variable number of arguments Write a function that returns...
1)
a) Write MATLAB function that accepts a positive integer
parameter n and returns a vector containing the values of the
integral (A) for n= 1,2,3,..., n. The function must use the
relation (B) and the value of y(1). Your function must preallocate
the array that it returns. Use for loop when writing your code.
b) Write MATLAB script that uses your function to calculate the
values of the integral (A) using the recurrence relation (B), y(n)
for n=1,2,... 19...
python
In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display the number n, the list of numbers, and a sub list of all the numbers in the list that are greater than the number n. Initialize the list and the number n in the main function of your code and call your function, passing the list and number as arguments. Run your code...
Using MATLAB Please
Write a MATLAB function that takes coord natos of four points as inputs and returns the coord nates of ntersection of the line passing through ooints 1 and 2 and the line passing through points 3 and 4. For function name and inout arguments, use: P line_int(P1, P2, P3, P4) The function should be able to handle row or column vector entries. This function will use a sub-function called line_eq. This sub-function takes coordinates of two points...
Write a user-defined MATLAB function that gives a random integer number within a range between two numbers. For the function name and arguments, use n = randint(a,b) where the two input arguments a and b are the two numbers and the output argument n is the random number. Use the function in the command window for the following: (a) Generate a random number between 1 and 49. (b) Generate a random number between -35 and -2
During lab 4, we have seen numerical implementation of Fourier Series for periodic signals. As first part of this assignment, you need to write a Matlab function that would take an array representing a single period of a signal (x), corresponding time array (t), and return the Fourier Series coefficients (Ck) in exponential form. The function should also be able to take two (2) optional input arguments: number of Fourier coefficients (Nk) and plot option (p). Use the template ‘fourier_series_exp.m’...
The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi and n, and retums two output arguments: a row vector of n2 elements and and n-by-n matrix. The two output arguments must contain the exact same set of random integers that fall between 1 and maxi Do this using the random number genertor, not by reshaping the data Example n,v-randi...
1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...
Need help problem 9-13
C++ Homework please help
WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...