MATLAB rookie help, How do i create a code to return these outputs?

조회 수: 2 (최근 30일)
Tessa
Tessa 2021년 4월 26일
편집: Tessa 2021년 4월 26일
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).

답변 (1개)

Steven Lord
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)
a = 25
b = 4
function [out1, out2] = myfun(in1)
out1 = in1.^2;
out2 = in1-1;
end
See this documentation page for more information.
  댓글 수: 1
Tessa
Tessa 2021년 4월 26일
That is just a sample program. Not what I’m trying to run. It’s just showing how to pass parameters to a sub function. I need a code to implement the equation based on values from the table

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by