Waves mode summation for a string
显示 更早的评论
I required to computer code for mode summation for a string with a length of 20, wave velocity of 3.
Here is my attempt:
clear all
clc
xs=8; % source position
v=3; % wave velocity
L=20; % length of string
ta=0.2; % tension of string
n=20; % number of nodes (we need to perform the summition for first 40 and 80 nodes.
% here i fixed the nodes for the seek of simplicity)
t=1; % time after the spring plucked,
omga=n*pi*v/L; % input source factor
F=exp(-((omga*ta).^2)/4); % force
x=0:0.01:20; % waves amplitude for distnace vary form 0 to 20
%x=x';
for i=1:length(x)
u(i)=sin(n*pi*xs/L)*F*sin(n*pi*x(i)/L)*cos(omga*t);
end
plot(x,u)
The above script produce this plot for n=20

This script works perfectly to generate the wave for a single node value (above figure). I required to generate the waves for node values varies between 1 to 40. For this i modifiy teh script as follows:
clear all
clc
xs=8;
v=3;
L=20;
ta=0.2;
t=1;
n=1:1:40;
x=0:0.1:20;
for j=1:length(n)
omga(j)=n(j)*pi*v/L;
F(j)=exp(-((n(j)*pi*v*ta).^2)/4);
for i=1:length(x)
u(i)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x(i)/L)*cos(omga(j)*t);
end
end
plot(x,u)
This output produce a single line where i required to plot all (x,u) for n=1:40. along with a summiation plot of all the waves nodes (bold one in the attched figure) 

采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

