is this code correct?
1 次查看(过去 30 天)
显示 更早的评论
finding y(t) for seconds in steps of 0.1 seconds.
given:
m = 25.0 kg, c is the damping factor = 5.0 N-s/m, k is the spring constant = 200.0 N/m, A = 5.0 m, B = 0.25 m.
code:
m=25;
c=5;
k=200;
A=5;
B=0.25;
t=0:0.1:10;
y = exp((-c/(2*m))*t).*(A*sin(sqrt((k/m)-((c/2*m)^2))*t)+cos(sqrt((k/m)-((c/2*m)^2))*t))
1 个评论
John D'Errico
2022-12-13
There was no need to post the same question twice, after only a few minutes of waiting. Are you that impatient to have an answer?
回答(2 个)
Jan
2022-12-13
The equation of an underdamped mass-spring-dashpot system is:
This does neither match
y = exp((-c/(2*m))*t).*(A*sin(sqrt((k/m)-((c/2*m)^2))*t)+cos(sqrt((k/m)-((c/2*m)^2))*t))
nor
So my bold guessing is that your code is not correct.
0 个评论
John D'Errico
2022-12-13
Why do you think something is wrong? :)
I really like the way Answers shows a symbolic expression in a nice viewable form. Often it can help to see if you have made a mistake in an expression. But a live script should do the same for you in MATLAB proper. Anyway, take a look at the formula below, and see if you notice anything strange. I did. I copied exactly the expression you wrote into the line below, though I did not assign the other parameters the values you have assigned, as that would make it difficult to know if you had made a mistake.
syms m c k A B t
y = exp((-c/(2*m))*t).*(A*sin(sqrt((k/m)-((c/2*m)^2))*t)+cos(sqrt((k/m)-((c/2*m)^2))*t))
Do you see a problem there? I do. It points out a mistake you made twice, in that
c/2*m
is NOT the same thing as
c/(2*m)
An easy mistake to make perhaps, especially in a long messy expression. Sometimes you can read a line of code over and over again, not seeing the obvious, because a missing pair of parens is easy to miss in a long line like that.
Next, look carefully. Is there a term with B in it? Is B begone? And then look more carefully yet, because A has been multiplied by the cosine term, not the sine term. So there were actually two more mistakes.
Again, the pretty display of an expression is a useful tool in problems like this.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!