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

Matlab code using ant colony algorithm, Ant Colony Optimization for Optimiz...

Ant Colony Optimization for Optimization of Route path taken Ant Colony Algorithm is a potential candidate for coupled, 3D optimisation. Ant Colony Algorithm enjoys the overall

Illustration of output statements, Illustration of Output statements: ...

Illustration of Output statements: For illustration, >> disp('Hello') Hello >> disp(4^3)   64 The formatted output can be printed to the screen by using the fpr

If-else statement, The IF-ELSE Statement: The if statement selects whe...

The IF-ELSE Statement: The if statement selects whether an action is executed or not. Selecting between the two actions, or selecting from numerous actions, is accomplished by

#numerical Analysis, using newton divided diference formula find f(15) and ...

using newton divided diference formula find f(15) and f (8)

Functions, Need help with creating functions in matlab.

Need help with creating functions in matlab.

Physics, how do you make a program for a parachute man falling to determine...

how do you make a program for a parachute man falling to determine his terminal velocity, having in consideration the drag force (cv^2). I have the formula to be v(i+1)=v(i)*delta(

What are the matlab system parts, The MATLAB system having of five main par...

The MATLAB system having of five main parts: * Handle Graphics. * The MATLAB working environment. * The MATLAB language. * The MATLAB mathematical function library.

Draw the histogram of the original image, Given the following image, ...

Given the following image, 1 2 1 1 2 0 0 1 5 1 0 1

Illustration of function functions, Illustration of Function functions: ...

Illustration of Function functions: For illustration, to pass the sin function into fplot, one would pass its handle as shown in figure for the result.   >> fplot(@s

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