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

1 view (last 30 days)
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.

Accepted Answer

Aquatris
Aquatris on 9 Apr 2024
Moved: Image Analyst on 9 Apr 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

More Answers (0)

Categories

Find more on Vibration Analysis in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!