Problem:
To be copied
Solution:
The differential equation is so easy so we can first solve it analytically, again, using Laplace transform.
First, let y(x)=ψ(x−1), that allow us to pose the initial condition at x=−1 to x=0.
y″=ψ″(x−1)=(β−100)ψ(x−1)=(β−100)yL(y″)=L((β−100)y)sL(y′)−y′(0)=(β−100)L(y)sL(y′)−1=(β−100)L(y)s(sL(y)−y(0))−1=(β−100)L(y)s(sL(y)−0)−1=(β−100)L(y)s2L(y)−1=(β−100)L(y)s2L(y)+(100−β)L(y)=1L(y)=1s2+(100−β)L(y)=1√(100−β)√(100−β)s2+(100−β)y=1√(100−β)sin(√(100−β)x)ψ(x)=1√(100−β)sin(√(100−β)(x+1))
Here is the MATLAB code for solving the ODE:
clear all; close all; clc
main driver (just paste into MATLAB)
tol = 10^(-4);
xspan = [-1 1];
A = 1;
ic = [0 A];
beta = 91;
[t y] = ode45('f_rhs', xspan, ic, [], beta);
plot(t, y(:,1))
y(end, 1)
and the function to be solved:
function rhs=f_rhs(x, ic, dummy, beta)
y1 = ic(1);
y2 = ic(2);
rhs = [y2;
(beta - 100)*y1];
this is the overall code for finding all eigenvalues
clear all; % clear all previously defined variables
close all; % clear all previously defined figures
tol=10^(-4); % define a tolerance level to be achieved by the shooting algorithm
col=[’r’,’b’,’g’,’c’,’m’,’k’]; % eigenfunction colors
n0=100; % define the parameter n0
A=1; % define the initial slope at x=-1
x0=[0 A]; % initial conditions: x1(-1)=0, x1’(-1)=A
xp=[-1 1]; % define the span of the computational domain
beta_start=n0; % beginning value of beta
for modes=1:5 % begin mode loop
beta=beta_start; % initial value of eigenvalue beta
dbeta=n0/100; % default step size in beta
for j=1:1000 % begin convergence loop for beta
[t,y]=ode45(’f_rhs’,xp,x0,[],n0,beta); % solve ODEs
if abs(y(end,1)-0) < tol % check for convergence
beta % write out eigenvalue
break % get out of convergence loop
end
if (-1)^(modes+1)*y(end,1)>0 % this IF statement block
beta=beta-dbeta; % checks to see if beta
else % needs to be higher or lower
beta=beta+dbeta/2; % and uses bisection to
dbeta=dbeta/2; % converge to the solution
end %
end % end convergence loop
beta_start=beta-0.1; % after finding eigenvalue, pick new starting value for next mode
norm=trapz(t,y(:,1).*y(:,1)) % calculate the normalization
plot(t,y(:,1)/sqrt(norm),col(modes)); hold on % plot modes
end % end mode loop
Now we can check with the analytic answers - note the output beta values actually lead to full/half cycle of the sine.
In order for ψ(1)=0, we need 1√(100−β)sin(2√(100−β))=0, of course that correspond to √100−β is a multiple of π2
To be copied
Solution:
The differential equation is so easy so we can first solve it analytically, again, using Laplace transform.
First, let y(x)=ψ(x−1), that allow us to pose the initial condition at x=−1 to x=0.
y″=ψ″(x−1)=(β−100)ψ(x−1)=(β−100)yL(y″)=L((β−100)y)sL(y′)−y′(0)=(β−100)L(y)sL(y′)−1=(β−100)L(y)s(sL(y)−y(0))−1=(β−100)L(y)s(sL(y)−0)−1=(β−100)L(y)s2L(y)−1=(β−100)L(y)s2L(y)+(100−β)L(y)=1L(y)=1s2+(100−β)L(y)=1√(100−β)√(100−β)s2+(100−β)y=1√(100−β)sin(√(100−β)x)ψ(x)=1√(100−β)sin(√(100−β)(x+1))
Here is the MATLAB code for solving the ODE:
clear all; close all; clc
main driver (just paste into MATLAB)
tol = 10^(-4);
xspan = [-1 1];
A = 1;
ic = [0 A];
beta = 91;
[t y] = ode45('f_rhs', xspan, ic, [], beta);
plot(t, y(:,1))
y(end, 1)
and the function to be solved:
function rhs=f_rhs(x, ic, dummy, beta)
y1 = ic(1);
y2 = ic(2);
rhs = [y2;
(beta - 100)*y1];
this is the overall code for finding all eigenvalues
clear all; % clear all previously defined variables
close all; % clear all previously defined figures
tol=10^(-4); % define a tolerance level to be achieved by the shooting algorithm
col=[’r’,’b’,’g’,’c’,’m’,’k’]; % eigenfunction colors
n0=100; % define the parameter n0
A=1; % define the initial slope at x=-1
x0=[0 A]; % initial conditions: x1(-1)=0, x1’(-1)=A
xp=[-1 1]; % define the span of the computational domain
beta_start=n0; % beginning value of beta
for modes=1:5 % begin mode loop
beta=beta_start; % initial value of eigenvalue beta
dbeta=n0/100; % default step size in beta
for j=1:1000 % begin convergence loop for beta
[t,y]=ode45(’f_rhs’,xp,x0,[],n0,beta); % solve ODEs
if abs(y(end,1)-0) < tol % check for convergence
beta % write out eigenvalue
break % get out of convergence loop
end
if (-1)^(modes+1)*y(end,1)>0 % this IF statement block
beta=beta-dbeta; % checks to see if beta
else % needs to be higher or lower
beta=beta+dbeta/2; % and uses bisection to
dbeta=dbeta/2; % converge to the solution
end %
end % end convergence loop
beta_start=beta-0.1; % after finding eigenvalue, pick new starting value for next mode
norm=trapz(t,y(:,1).*y(:,1)) % calculate the normalization
plot(t,y(:,1)/sqrt(norm),col(modes)); hold on % plot modes
end % end mode loop
Now we can check with the analytic answers - note the output beta values actually lead to full/half cycle of the sine.
In order for ψ(1)=0, we need 1√(100−β)sin(2√(100−β))=0, of course that correspond to √100−β is a multiple of π2
No comments:
Post a Comment