Hi there.
I'm having a little trouble implementing the solution to the damped 1-dimensional wave equation for a damped, plucked string. I would like to plot the position of a large number of points along the string (to represent the string itself), at discrete time instants.
My commented code is:
MATLAB code
L_s = 0.33; % length of string (m)
m = 0.000125; % mass of string (kg)
T = 68; % stretched tension of string (N)
R = 100; % linear resistance for string (Ns/m)
rho_L = m/L_s; % mass per unit length of string (kg/m)
c = sqrt(T/rho_L); % wave speed in string (m/s)
t = 1.3; % current time value (s)
d_0 = 0.2; % initial displacement value (m)
% range variables
x = linspace(0,L_s,1000); % position points on string (m)
n = linspace(1,length(x),length(x)); % integers for Fourier series
Omega_n = sqrt((c.*n.*pi./L_s).^2 - R^2); % argument coefficient for Fourier sine series
alpha_n = 8*d_0./(n.^2*pi^2).*sin(n.*pi./2); % first Fourier series coefficient
beta_n = R.*alpha_n./Omega_n; % second Fourier series coefficient
w = zeros(1,length(n),length(x)); % displacement function for string
for i = 1:length(n) for j = 1:length(x) w(i,j) = w + sin(n(i).*pi.*x(j)./L_s).*exp(-R./t).*(alpha_n(i).*cos(Omega_n(i).*t) ... + beta_n(i).*sin(Omega_n(i).*t)); endendhold onfigure(1)plot(x,w)xlabel('Position on string (m)')ylabel('Displacement (m)')xlim([0 0.33])
The error message is: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in ass_assignment2 (line 39) w(i,j) = w + sin(n(i).*pi.*x(j)./L_s).*exp(-R./t).*(alpha_n(i).*cos(Omega_n(i).*t) …"
Could anyone offer some advice? I understand the error message is telling me that the RHS comprises more dimensions than the LHS, but I cannot see why this would be.
Any help is much appreciated. Any general comments on more efficient and clearer coding techniques are also most welcome.
Regards,
Mike
Best Answer