Homework Help, Basic function
显示 更早的评论
Create the function [t v] = velinput that asks the user to enter the following inputs: M = Mass (kg) g = gravity (m/s 2 ) Cd = drag coefficient (kg/m) Tend = End Time N = number of points in time Show = Plot Function (Y or N) Set the initial time to zero
So, I understand all the inputting part. I just don't understand the use of function. I tried help function and that didn't help to much either. Im just really stuck.
回答(2 个)
Geoff Hayes
2016-2-28
cwachts - the first line of your assignment is giving you the function name and signature. In the MATLAB editor, create a new file and then let the following be your first line of code
function [t v] = velinput
From the menu, save the file and it should be saved with the name of your function as velinput.m. When you run this function, you will do so from the command prompt by typing in
>> velinput
The body of your function will have all of the code necessary to request some information from the user and to build the plot.
Roger Stafford
2016-2-28
Though the statement of the problem doesn't appear to require a computation which uses these inputs, I would think doing so would be implicit upon receiving a 'Y' for 'Show'. To do the computation will require the solution of a differential equation to solve for velocity versus time, courtesy of Isaac Newton and his laws of motion. You can probably use 'ode45'. See
http://www.mathworks.com/help/matlab/ref/ode45.html
for details.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!