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

2 visualizaciones (últimos 30 días)
Tessa
Tessa el 26 de Abr. de 2021
Editada: Tessa el 26 de Abr. de 2021
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).

Respuestas (1)

Steven Lord
Steven Lord el 26 de Abr. de 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)
a = 25
b = 4
function [out1, out2] = myfun(in1)
out1 = in1.^2;
out2 = in1-1;
end
See this documentation page for more information.
  1 comentario
Tessa
Tessa el 26 de Abr. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Assembly en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by