Using user defined Function with a Table of variables , through a For Loop
Ältere Kommentare anzeigen
I need to use my function=func(R,H,V,Vm) in a for loop and calls each of the 5 rows of R,H,V values from a provided 3x5 table and W is hard coded as Vm=1000.
I'm rusty on my 'for loops' and could not get it to work correctly.
Here is the assignment: 1. Write a function that calculates the launch angle, given the target range, altitude and velocity and cannon’s muzzle velocity. Function specifications: Input arguments: Range (R) in meters; Altitude (H) in meters; Target velocity (V) in m/s; Muzzle velocity (Vm) in m/s [the arguments must be in this order and the tolerance must be 0.001 or better.] Output argument: The required launch angle in degrees. Use the following test case to validate your function: R = 7,000 m; H = 2,500 m; V = 225 m/s; Vm = 1,000 m/s theta = 25.65 2. Write a script to apply your function from task 1 to a set of provided target data. a. Load the target data from the provided Excel file, targets.xlsx, into a matrix using the command data = xlsread(‘targets.xlsx’); • Each row of the data file contains the parameters for one target, in the following order: Range, Altitude, Velocity • Use a fixed value of 1,000 m/s for Vm.
b. Loop over the targets, calling the iterative solver function to determine the launch angle for each one. • Extract the parameters from the data array that you created in 2a; do not hard-code the numbers or the number of targets. (In other words, your program should work just as well if applied to a different data file.) • Store the solutions (the calculated launch angles) in a row vector called angles.
2 Kommentare
Image Analyst
am 8 Okt. 2018
Clear as mud. Please provide the inputs X, Y, and Z, and provide the desired output. Also provide the unnamed "provided 3x5 table" - provided to you maybe but you didn't provide it to us. For now about all I can say is
W=1000
for k = 1 : whatever
output = func(W, X, Y, Z)
end
Alan Austin
am 8 Okt. 2018
Bearbeitet: Alan Austin
am 8 Okt. 2018
Antworten (1)
Peter Perkins
am 12 Okt. 2018
0 Stimmen
If "table" means the table data type, then rowfun is designed for exactly this. Of course, it doesn't really stay within the lines of the assignment ...
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!