MATLAB rookie help, How do i create a code to return these outputs?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Steven Lord
2021년 4월 26일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Assembly에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!