Asked to plot using vectors of unequal sizes
2 ビュー (過去 30 日間)
古いコメントを表示
I am working on the following problem:
========================================
We wish to examine the motion of a damped harmonic oscillator. The small amplitude oscillation of a unit mass attached to a spring is given by the formula y = e−(R/2)t sin(ω1t ), where ω2 1 = ω2 o − R2/4 is the square of the natural frequency of the oscillation with damping (i.e., with resistance to motion); ω2 o = k is the square of the natural frequency of undamped oscillation; k is the spring constant; and R is the damping coefficient. Consider k = 1 and vary R from 0 to 2 in increments of 0.5. Plot y versus t for t from 0 to 10 in increments of 0.1.
========================================
My main problem with this problem is that I am told to evaluate y for R=0:0.5:2, but plot over the range of t=0:0.1:10. How can this work, if y is 1x5 and t is 1x101?
Here is my code, minus the line for t, which I make the same as R to get y, but then try to change when going to plot (doesn't work):
========================================
k= 1; %spring constant
R=[0:0.5:2]; %damping coeff
w0=sqrt(k);
w1=sqrt((w0^2)-R.^2/4);
y=exp(-(R./2).*t).*(sin(w1.*t));
plot(t,y)
0 件のコメント
採用された回答
Mischa Kim
2014 年 2 月 10 日
編集済み: Mischa Kim
2014 年 2 月 10 日
B.M., simply compute y in a for-loop and plot the results in the same figure using hold all. You also might want to include markers and a legend for readability. Use colors and markers to specify the color and marker type for each of the plots.
k = 1; %spring constant
R = 0:0.5:2; %damping coeff
t = 0:0.1:10;
w0 = sqrt(k);
w1 = sqrt((w0^2)-R.^2/4);
figure
hold all; grid; box
colors = 'krbcy';
markers = 'x+*.o';
for ii = 1:length(R)
y(ii,:) = exp(-(R(ii)/2).*t).*(sin(w1(ii)*t));
plot(t,y(ii,:),[markers(ii) colors(ii)]);
end
xlabel('t in s')
ylabel('y in TBD')
legend('R0','R1','R2','R3','R4')
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!