ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ
ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ

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

์กฐํšŒ ์ˆ˜: 2 (์ตœ๊ทผ 30์ผ)
Riley
Riley 2024๋…„ 4์›” 9์ผ
๋Œ“๊ธ€: Riley 2024๋…„ 4์›” 9์ผ
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.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Aquatris
Aquatris 2024๋…„ 4์›” 9์ผ
์ด๋™: Image Analyst 2024๋…„ 4์›” 9์ผ
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
  ๋Œ“๊ธ€ ์ˆ˜: 1
Riley
Riley 2024๋…„ 4์›” 9์ผ
Wow I am stupid I looked at this for so long and it was so simple thank you very much!

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Programming์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ

Community Treasure Hunt

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

Start Hunting!

Translated by