MATLAB rookie help, How do i create a code to return these outputs?
2 views (last 30 days)
Show older comments
My^''+By^'+Ky=x(t)
K = spring constant
B = dampening constant
M = mass
T = time
X = forcing function
Y = position of the mass
If you are given K, B, and M along with a table that gives values of x for a given t;
t (sec) [ 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2]
x ( kg m/s^2) [0 0 0.1 0.2 0.3 0.18 0.1 0 0 0 0]
Write a program that K, B and M are constant and supplied by the user input. Use T as the ending time value that solutions are sought ( also entered by the user when calling the function.
Initial values are t = 0 , y(0) = 0 , y’(0) = 0
The program outputs a flag ( runs without issue flag = 0) , t (vector of time values), y ( vector of position values), and yp ( vector of derivative values).
0 Comments
Answers (1)
Steven Lord
on 26 Apr 2021
You've omitted a function declaration line at the top of the file. That will turn the file from a script file (which cannot return outputs) into a function file (which can.) Use the declaration of the myfun function as a model.
To return multiple outputs, use square brackets like the myfun function below.
[a, b] = myfun(5)
function [out1, out2] = myfun(in1)
out1 = in1.^2;
out2 = in1-1;
end
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!