Waves mode summation for a string

조회 수: 1 (최근 30일)
Andi
Andi 2022년 1월 21일
댓글: KSSV 2022년 1월 21일
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)

채택된 답변

KSSV
KSSV 2022년 1월 21일
xs=8;
v=3;
L=20;
ta=0.2;
t=1;
n=1:1:40;
x=0:0.1:20;
omga = zeros(1,length(n)) ;
F = zeros(1,length(n)) ;
u = zeros(length(n),length(x)) ;
for j=1:length(n)
omga(j)=n(j)*pi*v/L;
F(j)=exp(-((n(j)*pi*v*ta).^2)/4);
u(j,:)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x/L)*cos(omga(j)*t); % no loop needed
end
us = sum(u) ;
plot(x,us)
  댓글 수: 2
Andi
Andi 2022년 1월 21일
The output (attached figure) of your proposed script is only valid for n=1.
Where the required output should be like this:
KSSV
KSSV 2022년 1월 21일
The code given by you is edited to get the sum. It is your job to check what you have missed in the code. The other mode number values are very less. You have to check your formula and the constant values given.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by