Borrar filtros
Borrar filtros

Ive completed code for an assignment but receive strange answers any help?

3 visualizaciones (últimos 30 días)
For each of the previous parts of the project, we have focused on reading in input arguments that were vectors and
providing output vectors of the same size. For this function, we will look at an input for a single truck. As such,
this function will work for a single value for the damping ratio, the natural and damped frequencies, and the initial
displacement. To remind you that these will be scalar input arguments, we will designate them with an N after the
variable names.
For free-damped vibration, we can find the resulting vibration caused by an initial displacement x0N by using the
following equations.
𝑠1 = 𝜔𝑛𝜁 𝜔𝑑𝑖
𝑠2 = 𝜔𝑛𝜁 + 𝜔𝑑𝑖
In these equations, the values of 𝑠1 and 𝑠2 are called the roots of the characteristic equation. Yes! The 𝒊 in both
of these equations is 𝟏. This is something you will learn about in the future if you take the Math Methods or
Ordinary Differential Equations courses. For our situation, let’s assume that we are releasing each truck from rest
when the applied force is removed. That means that our initial velocity of each truck is zero (the provided
equations already take this into account). If this is the case, you can find the resulting displacement as a function
of time (as a function of time, not multiplied by time!!) using the following equations.
𝐶1 = 𝑠2𝑥0
𝑠1 𝑠2
𝐶2 = 𝑥0 𝐶1
𝑥(𝑡) = 𝐶1𝑒(𝑠1𝑡) + 𝐶2𝑒(𝑠2𝑡)
This equation will require you to understand how to use the exp function because the 𝑒 in our equation is Euler’s
number. Your function will accept input arguments of zetaN, wnN, wdN, and x0N (all of which are scalars), as
well as a vector t. For our project, we are going to assume that zetaN is not equal to zero! That will result in 𝐶1
being infinite. Your function will return a vector of displacement values xN, according to the above equations,
which is the same size as vector t. You should use the below function header. Don’t forget the required comments!
function xN=motionN_XXX(zetaN,wnN,wdN,x0N,t)
Don’t let the equations and the number of inputs confuse you! You have the equations. You know what to do!
The code I have written is
function xN=motionN_RR(zetaN,wnN,wdN,xoN,t)
%
s1=-wnN*zetaN-wdN*i
s2=-wnN*zetaN-wdN*i
c1=(s2*xoN)/(s1-s2)
c2=xoN-c1
xN(t)=(c1*exp(s1*t))+(c2*exp(s2*t))
end
This is an intro class and she explained we might get weird answers and thats okay but i keep getting NaN. We havent covered problems like this and im unsure if the answers im getting make sense or if i mistyped the code or what. Any help would be appreciated.

Respuesta aceptada

Aquatris
Aquatris el 9 de Abr. de 2024
Movida: Image Analyst el 9 de Abr. de 2024
You are getting NaN because your s1 is equal to s2:
s1=-wnN*zetaN-wdN*i
s2=-wnN*zetaN-wdN*i
where you forgot the ...+wdN*i for s2.
Then c1 becomes a division by zero since s1-s2=0:
c1=(s2*xoN)/(s1-s2)
which is a NaN

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by