Using user defined Function with a Table of variables , through a For Loop
显示 更早的评论
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 个评论
Image Analyst
2018-10-8
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
2018-10-8
编辑:Alan Austin
2018-10-8
回答(1 个)
Peter Perkins
2018-10-12
0 个投票
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 ...
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!