Crank-nicolson method, MATLAB Programming

Assignment Help:

 

clear

tic

L=1;

T=0.2;

nust=2000;

dt=T/nust;

n=40;

dx=L/n;

 

r=1;

 omega=10:10:5000;%Store Range of Frequencies for Simulation

u=zeros(n+1,nust+1);%Initialize the grid (Space along rows/dim1& time along cols/dim2)

% Bar Boundary Condition

time=zeros(1,nust+1);%Time Elapsed Vector

for k=1:nust+1

u(1,k)=0;

u(n+1,k)=0;

time(k)=(k-1)*dt;

end

% Bar Initial Condition

x=zeros(n+1,1);%Length Vector

fori=1:n+1

x(i)=(i-1)*dx;

u(i,1)=sin(pi*x(i));

end

%constructing the Matrix in the right side

ar(1:n-2)=r;

br(1:n-1)=2-2*r;

cr(1:n-2)=r;

Mr=diag(br,0)+diag(ar,-1)+diag(cr,1);

 

%constructing the Matrix in the left side

al(1:n-2)=-r;

bl(1:n-1)=2+2*r;

cl(1:n-2)=-r;

Ml=diag(bl,0)+diag(al,-1)+diag(cl,1);

%aa=Ml\Mr;

 

% Crank Nicolson Implementation

u_sol=zeros(length(u(:,1)),length(u(1,:)),length(omega));

forll=1:length(omega)

for k=2: nust

        C=0.5*dt*(cos(omega(ll)*k*dt)+cos(omega(ll)*(k+1)*dt))*ones(length(2:n),1);

uu=u(2:n,k-1);

        u(2:n,k)=inv(Ml)*((Mr*uu)+C);

end

u_sol(:,:,ll)=u;

    clear uu;

end

 

figure;

subplot(2,1,1); mesh(x,time,u_sol(:,:,1)')

title(['Solution for omega=',num2str(omega(1))]);

subplot(2,1,2); mesh(x,time,u_sol(:,:,end)')

title(['Solution for omega=',num2str(omega(end))]);

xlabel('x-axis');

ylabel('Temperature');

toc

The code you have provided me at that time was giving the out of the whole process( as a plot ) which isgood but we cannot specify a point in the rod to find the temperature , for example if we need to know the temperature at the distance 0.5 ( we know the total length is 1) there is no way to get it . so what I need is the following :

We have a rod with a length of 1 and we want to know the temperature at the center of the rod ( we may change the point we want to know ) and the output must be a number not a plot , I mean I want the MATLAB to tell me the temperature at the specified point.


Related Discussions:- Crank-nicolson method

Calculate the mean-mode and median, You are given data similar to the examp...

You are given data similar to the examples and sample problems in the statistics topic. Write MATLAB program to do the following: 1. Plot histogram, relative frequency histogram

#GUI, #create a matlab GUI for designing common emitter amplifier which pro...

#create a matlab GUI for designing common emitter amplifier which produces AC load lines based on the component values

Generates sin or cos wave using plot functions, Generates sin or cos wave u...

Generates sin or cos wave using plot functions: The script generates an x vector; iterating through all the values from 0 to 2*π in steps of 2*π /40 gives sufficient points to

Analytical solution and numerical solution, using 0de 45 how can i get the ...

using 0de 45 how can i get the anlytical and numerical solutions for an equation,,

Rc phase shift oscillater, design a rc phase shift oscillator for a particu...

design a rc phase shift oscillator for a particular frequency of oscillation and generate a sinusoidal signal

Homework, Given , provide solutions for the following systems of equations ...

Given , provide solutions for the following systems of equations a) , 1.0 10.5 0.5 9 0.5 3.25 5.25 2.5 2 13 5 6 ? ? ? ? ? ? ? ? ? ? ? A ? ? ? ? ? ? ? ? ? ? ? ? 3 7 16 b b) , 1.0 10

Matlab code to run simulations of a batch reactor , Background Protein ther...

Background Protein therapeutics are a major component of the biotechnology industry, with sales estimated in the range of ~$99bn annually (2011) and steady market growth. Many phar

Illustrations of if statement, Illustrations of if statement: illustra...

Illustrations of if statement: illustrations of running this script: >> sqrtifexamp Please enter a number: -4.2 The sqrt of 4.2 is 2.0 >> sqrtifexamp Please ent

Digging the dirt - autonomous mining robots , Digging the Dirt: Autonomous...

Digging the Dirt: Autonomous Mining Robots   Mining is a multi-billion dollar industry and a critical part of the Australian economy. Much of the day-to-day work on mining sites

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd