SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
ME 372 Computer-Aided Mechanical Engineering
Instructor: Emre Alpman
Assignment #3
Due Date: Mar 16th, 2011
SECOND ORDER ACCURATE SCHEMES
Summary of the Previous Assignment
In Assignment #2, the main goal was to analyze the effect of local error on the solution accuracy with
the aim of controlling it. A desired tolerance on the local error was set by dtol which was then used to
adjust the stepsize that produces it.
For this purpose the module accuracy.m was developed according to the algorithm given in
Assignment #2. This module is given in Table 1.
Table 1. Module accuracy.m
% This module adjusts the step size according to the given 
% error tolerance dtol
% Inputs: Step sizei error tolerance, initial time and condition
% Outputs: Adjusted time step
function [hnew] = accuracy(h,dtol,t0,y0)
hnew  = h ;
yh = y0 + hnew*deriv(t0,y0) ;         % one step solution
ymid  =  y0 + hnew/2*deriv(t0,y0);     % take half an euler step        
tmid = t0+hnew/2;
yh2  = ymid + hnew/2*deriv(tmid,ymid) ;  % two step solution
local_err = norm((yh2­yh),Inf)/norm(yh2,Inf) % Local error
% Repeat the above steps by dividing the step size by 2 until
% relative error becomes small enough
while local_err > dtol
   hnew      = hnew/2 ;
   yh      = ymid ;
   ymid  =  y0 + hnew/2*deriv(t0,y0);              
   tmid = t0+hnew/2;
   yh2  = ymid + hnew/2*deriv(tmid,ymid) ;  
   local_err = norm((yh2­yh),Inf)/norm(yh2,Inf)
end
The above routine is called by hw2_main.m before the solution loop starts. The modified
hw2_main.m is given in Table 2.
Table 2. Module hw2_main.m
% main program for hw2
clear all;
% assignments
t0 =  0.0 ;  % starting time
tf = 20. ;  % final time
h  =  0.2 ;  % time step size
ctol = 0.001; % Error tolerance for BE
% Open a file to write the data in
filename = 'data.txt' ;
fid = fopen (filename, 'w+');
fprintf (fid,'time approximate exactn');
% initial conditions
y0 = [10.*pi/180; 0.0];
% initialization
i = 0  ;   % loop step counter
y = y0 ;   % current state = initial state
t = t0 ;   % current time  = initial time
fprintf (fid,'%3i %6.4f  %6.4fn',t,y(1),y0(1));
% Exact Solution
yexact = exact(t0, y0);
figure(1) ;
plot(t,y(1), 'ro',t,yexact,'b*'); 
grid;
axis([0 20 ­0.2 0.2])
hold;
% Adjust time step by controlling the local error
h = accuracy(h,0.01,t0,y0)
tic
% time loop
while ( t < tf )
    % Obtain the solution 
    [t,y] = beuler(h,t,y, ctol) ;
    % Exact Solution
    yexact = exact(t,y0);
    % Write data to the file
    fprintf (fid,' %4.2f  %6.4f   %6.4fn',t,y(1),yexact(1));
    % Plot data
    plot(t,y(1),'ro', t,yexact(1),'b*') ;
end
toc
fclose(fid) ;
Here h started from 0.2 and dropped to 0.05. The drop of the local error is given in Table 3.
Table 3. Local error
local_err = 0.074895
local_err = 0.025799
local_err = 0.0063613
h = 0.050000
The Backward Euler solution with the adjusted step-size is given in Figure 1.
Figure 1. Comparison of numerical solution ( red circles) with analytical solution.
Lab Assignment
In this assignment, you are expected to implement the explicit midpoint and explicit trapezoidal
methods. The formulations for the above methods are given in equations 1 and 2, respectively.
yk1/2= yk
h
2
f tk , yk
yk1=ykh f tk1/2, yk1/2
(1)
yk1
0
= ykh f tk , yk
yk1=yk
h
2
f tk , yk f tk1, yk1
0

(2)
You will write two separate modules named midp.m and trap.m that use Eq. 2 and set of Eqs. 3,
respectively. These modules should be able to replace previous beuler.m module, just by changing its
name in the main program.
In this lab we will compare the methods we have studied for their accuracy. Start with h = 0.02 and
adjust the stepsize with accuracy.m using dtol = 0.01. Then plot and compare angular displacement
with the exact solution for Forward Euler, Backward Euler, Midpoint and Trapezoidal methods.
Homework Assignment
Generate a module for the implicit Trapezoidal method:
yk1=yk
h
2
f tk , yk f tk1 , yk1 (3)
Since the above method is implicit you would need to generate an iterative solution procedure similar
to the one we have done for the Backward Euler method. Compare the performance of explicit and
implicit trapezoidal methods by plotting and tabulating the exact absolute error with respect to time.
We can define the exact absolute error as:
Et =∣exact t−approximate t∣ (4)
Also compare them in terms of the computational time.

Más contenido relacionado

Similar a Assignment 3

CollidingParticles.pdf
CollidingParticles.pdfCollidingParticles.pdf
CollidingParticles.pdfDevidasKhatri
 
Modelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptx
Modelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptxModelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptx
Modelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptxKadiriIbrahim2
 
Animation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experienceAnimation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experienceVíctor Quezada
 
LAB05ex1.mfunction LAB05ex1m = 1; .docx
LAB05ex1.mfunction LAB05ex1m = 1;                          .docxLAB05ex1.mfunction LAB05ex1m = 1;                          .docx
LAB05ex1.mfunction LAB05ex1m = 1; .docxsmile790243
 
Robert_Tanner_Temperature_Distribution
Robert_Tanner_Temperature_DistributionRobert_Tanner_Temperature_Distribution
Robert_Tanner_Temperature_DistributionRobert Tanner
 
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docxLab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docxsmile790243
 
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docxCALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docxRAHUL126667
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And ConquerUrviBhalani2
 
MATLAB ODE
MATLAB ODEMATLAB ODE
MATLAB ODEKris014
 

Similar a Assignment 3 (20)

CollidingParticles.pdf
CollidingParticles.pdfCollidingParticles.pdf
CollidingParticles.pdf
 
Modelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptx
Modelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptxModelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptx
Modelling using differnt metods in matlab2 (2) (2) (2) (4) (1) (1).pptx
 
numerical.ppt
numerical.pptnumerical.ppt
numerical.ppt
 
Animation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experienceAnimation as-the-final-step-in-the-dynamics-experience
Animation as-the-final-step-in-the-dynamics-experience
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
 
Fluids_Final
Fluids_FinalFluids_Final
Fluids_Final
 
Matlab lab.pdf
Matlab lab.pdfMatlab lab.pdf
Matlab lab.pdf
 
LAB05ex1.mfunction LAB05ex1m = 1; .docx
LAB05ex1.mfunction LAB05ex1m = 1;                          .docxLAB05ex1.mfunction LAB05ex1m = 1;                          .docx
LAB05ex1.mfunction LAB05ex1m = 1; .docx
 
Robert_Tanner_Temperature_Distribution
Robert_Tanner_Temperature_DistributionRobert_Tanner_Temperature_Distribution
Robert_Tanner_Temperature_Distribution
 
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docxLab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
 
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docxCALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
ilovepdf_merged
ilovepdf_mergedilovepdf_merged
ilovepdf_merged
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
CMT
CMTCMT
CMT
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
Term project
Term projectTerm project
Term project
 
MATLAB ODE
MATLAB ODEMATLAB ODE
MATLAB ODE
 

Más de Ersin Tukenmez

İDARE 2 VİZE-FİNAL-kilidi açıldı.pdf
İDARE 2   VİZE-FİNAL-kilidi açıldı.pdfİDARE 2   VİZE-FİNAL-kilidi açıldı.pdf
İDARE 2 VİZE-FİNAL-kilidi açıldı.pdfErsin Tukenmez
 
ÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdf
ÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdfÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdf
ÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdfErsin Tukenmez
 
İCRA HUKUKU 15 KASIM 2021.docx
İCRA HUKUKU  15 KASIM 2021.docxİCRA HUKUKU  15 KASIM 2021.docx
İCRA HUKUKU 15 KASIM 2021.docxErsin Tukenmez
 
İCRA HUKUKU 15 KASIM 2021 (1).docx
İCRA HUKUKU  15 KASIM 2021 (1).docxİCRA HUKUKU  15 KASIM 2021 (1).docx
İCRA HUKUKU 15 KASIM 2021 (1).docxErsin Tukenmez
 
İDARE HUKUKU PRATİK CEVAPLARI.docx
İDARE HUKUKU PRATİK CEVAPLARI.docxİDARE HUKUKU PRATİK CEVAPLARI.docx
İDARE HUKUKU PRATİK CEVAPLARI.docxErsin Tukenmez
 
İCRA HUKUKU 16 KASIM (1).docx
İCRA HUKUKU 16 KASIM (1).docxİCRA HUKUKU 16 KASIM (1).docx
İCRA HUKUKU 16 KASIM (1).docxErsin Tukenmez
 
İCRA HUKUKU 16 KASIM.docx
İCRA HUKUKU 16 KASIM.docxİCRA HUKUKU 16 KASIM.docx
İCRA HUKUKU 16 KASIM.docxErsin Tukenmez
 
Tüm hasta Eğitim Formları Cerrahi.docx
Tüm hasta Eğitim Formları Cerrahi.docxTüm hasta Eğitim Formları Cerrahi.docx
Tüm hasta Eğitim Formları Cerrahi.docxErsin Tukenmez
 
Eğitim Planı Formu.docx
Eğitim Planı Formu.docxEğitim Planı Formu.docx
Eğitim Planı Formu.docxErsin Tukenmez
 
Eğitim Planı Formu (1).docx
Eğitim Planı Formu (1).docxEğitim Planı Formu (1).docx
Eğitim Planı Formu (1).docxErsin Tukenmez
 
Egitim plani formu(dilara2).docx
Egitim plani formu(dilara2).docxEgitim plani formu(dilara2).docx
Egitim plani formu(dilara2).docxErsin Tukenmez
 
Egitim plani formu(dilara2) (1).docx
Egitim plani formu(dilara2) (1).docxEgitim plani formu(dilara2) (1).docx
Egitim plani formu(dilara2) (1).docxErsin Tukenmez
 
Eğitim Planı Formu Dahiliye.docx
Eğitim Planı Formu Dahiliye.docxEğitim Planı Formu Dahiliye.docx
Eğitim Planı Formu Dahiliye.docxErsin Tukenmez
 
Eğitim Planı Formu Dahiliye (1).docx
Eğitim Planı Formu Dahiliye (1).docxEğitim Planı Formu Dahiliye (1).docx
Eğitim Planı Formu Dahiliye (1).docxErsin Tukenmez
 
Bizim_Toptan_Satis_Magazalari_AS.docx
Bizim_Toptan_Satis_Magazalari_AS.docxBizim_Toptan_Satis_Magazalari_AS.docx
Bizim_Toptan_Satis_Magazalari_AS.docxErsin Tukenmez
 
Ise 455 2021 midterm question 3
Ise 455 2021 midterm   question 3Ise 455 2021 midterm   question 3
Ise 455 2021 midterm question 3Ersin Tukenmez
 
Ise 455 2021 final question 1 and 2
Ise 455 2021 final question 1 and 2Ise 455 2021 final question 1 and 2
Ise 455 2021 final question 1 and 2Ersin Tukenmez
 

Más de Ersin Tukenmez (20)

İDARE 2 VİZE-FİNAL-kilidi açıldı.pdf
İDARE 2   VİZE-FİNAL-kilidi açıldı.pdfİDARE 2   VİZE-FİNAL-kilidi açıldı.pdf
İDARE 2 VİZE-FİNAL-kilidi açıldı.pdf
 
ÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdf
ÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdfÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdf
ÇOCUKLUK ÇAĞININ DÖKÜNTÜLÜ HASTALIKLARI.pdf
 
İCRA HUKUKU 15 KASIM 2021.docx
İCRA HUKUKU  15 KASIM 2021.docxİCRA HUKUKU  15 KASIM 2021.docx
İCRA HUKUKU 15 KASIM 2021.docx
 
İCRA HUKUKU 15 KASIM 2021 (1).docx
İCRA HUKUKU  15 KASIM 2021 (1).docxİCRA HUKUKU  15 KASIM 2021 (1).docx
İCRA HUKUKU 15 KASIM 2021 (1).docx
 
İDARE HUKUKU PRATİK CEVAPLARI.docx
İDARE HUKUKU PRATİK CEVAPLARI.docxİDARE HUKUKU PRATİK CEVAPLARI.docx
İDARE HUKUKU PRATİK CEVAPLARI.docx
 
İCRA HUKUKU 16 KASIM (1).docx
İCRA HUKUKU 16 KASIM (1).docxİCRA HUKUKU 16 KASIM (1).docx
İCRA HUKUKU 16 KASIM (1).docx
 
İCRA HUKUKU 16 KASIM.docx
İCRA HUKUKU 16 KASIM.docxİCRA HUKUKU 16 KASIM.docx
İCRA HUKUKU 16 KASIM.docx
 
Tüm hasta Eğitim Formları Cerrahi.docx
Tüm hasta Eğitim Formları Cerrahi.docxTüm hasta Eğitim Formları Cerrahi.docx
Tüm hasta Eğitim Formları Cerrahi.docx
 
Eğitim Planı Formu.docx
Eğitim Planı Formu.docxEğitim Planı Formu.docx
Eğitim Planı Formu.docx
 
Eğitim Planı Formu (1).docx
Eğitim Planı Formu (1).docxEğitim Planı Formu (1).docx
Eğitim Planı Formu (1).docx
 
Egitim plani formu(dilara2).docx
Egitim plani formu(dilara2).docxEgitim plani formu(dilara2).docx
Egitim plani formu(dilara2).docx
 
Egitim plani formu(dilara2) (1).docx
Egitim plani formu(dilara2) (1).docxEgitim plani formu(dilara2) (1).docx
Egitim plani formu(dilara2) (1).docx
 
Eğitim Planı Formu Dahiliye.docx
Eğitim Planı Formu Dahiliye.docxEğitim Planı Formu Dahiliye.docx
Eğitim Planı Formu Dahiliye.docx
 
Eğitim Planı Formu Dahiliye (1).docx
Eğitim Planı Formu Dahiliye (1).docxEğitim Planı Formu Dahiliye (1).docx
Eğitim Planı Formu Dahiliye (1).docx
 
Bizim_Toptan_Satis_Magazalari_AS.docx
Bizim_Toptan_Satis_Magazalari_AS.docxBizim_Toptan_Satis_Magazalari_AS.docx
Bizim_Toptan_Satis_Magazalari_AS.docx
 
Quiz 1 solutions
Quiz 1 solutionsQuiz 1 solutions
Quiz 1 solutions
 
Ise 455 lecture 10
Ise 455 lecture 10Ise 455 lecture 10
Ise 455 lecture 10
 
Ise 455 2021 midterm question 3
Ise 455 2021 midterm   question 3Ise 455 2021 midterm   question 3
Ise 455 2021 midterm question 3
 
Ise 455 2021 final question 1 and 2
Ise 455 2021 final question 1 and 2Ise 455 2021 final question 1 and 2
Ise 455 2021 final question 1 and 2
 
6 propagation ap
6 propagation ap6 propagation ap
6 propagation ap
 

Assignment 3

  • 1. ME 372 Computer-Aided Mechanical Engineering Instructor: Emre Alpman Assignment #3 Due Date: Mar 16th, 2011 SECOND ORDER ACCURATE SCHEMES Summary of the Previous Assignment In Assignment #2, the main goal was to analyze the effect of local error on the solution accuracy with the aim of controlling it. A desired tolerance on the local error was set by dtol which was then used to adjust the stepsize that produces it. For this purpose the module accuracy.m was developed according to the algorithm given in Assignment #2. This module is given in Table 1. Table 1. Module accuracy.m % This module adjusts the step size according to the given  % error tolerance dtol % Inputs: Step sizei error tolerance, initial time and condition % Outputs: Adjusted time step function [hnew] = accuracy(h,dtol,t0,y0) hnew  = h ; yh = y0 + hnew*deriv(t0,y0) ;         % one step solution ymid  =  y0 + hnew/2*deriv(t0,y0);     % take half an euler step         tmid = t0+hnew/2; yh2  = ymid + hnew/2*deriv(tmid,ymid) ;  % two step solution local_err = norm((yh2­yh),Inf)/norm(yh2,Inf) % Local error % Repeat the above steps by dividing the step size by 2 until % relative error becomes small enough while local_err > dtol    hnew      = hnew/2 ;    yh      = ymid ;    ymid  =  y0 + hnew/2*deriv(t0,y0);                  tmid = t0+hnew/2;    yh2  = ymid + hnew/2*deriv(tmid,ymid) ;      local_err = norm((yh2­yh),Inf)/norm(yh2,Inf) end
  • 2. The above routine is called by hw2_main.m before the solution loop starts. The modified hw2_main.m is given in Table 2. Table 2. Module hw2_main.m % main program for hw2 clear all; % assignments t0 =  0.0 ;  % starting time tf = 20. ;  % final time h  =  0.2 ;  % time step size ctol = 0.001; % Error tolerance for BE % Open a file to write the data in filename = 'data.txt' ; fid = fopen (filename, 'w+'); fprintf (fid,'time approximate exactn'); % initial conditions y0 = [10.*pi/180; 0.0]; % initialization i = 0  ;   % loop step counter y = y0 ;   % current state = initial state t = t0 ;   % current time  = initial time fprintf (fid,'%3i %6.4f  %6.4fn',t,y(1),y0(1)); % Exact Solution yexact = exact(t0, y0); figure(1) ; plot(t,y(1), 'ro',t,yexact,'b*');  grid; axis([0 20 ­0.2 0.2]) hold; % Adjust time step by controlling the local error h = accuracy(h,0.01,t0,y0) tic % time loop while ( t < tf )     % Obtain the solution      [t,y] = beuler(h,t,y, ctol) ;     % Exact Solution     yexact = exact(t,y0);     % Write data to the file
  • 3.     fprintf (fid,' %4.2f  %6.4f   %6.4fn',t,y(1),yexact(1));     % Plot data     plot(t,y(1),'ro', t,yexact(1),'b*') ; end toc fclose(fid) ; Here h started from 0.2 and dropped to 0.05. The drop of the local error is given in Table 3. Table 3. Local error local_err = 0.074895 local_err = 0.025799 local_err = 0.0063613 h = 0.050000 The Backward Euler solution with the adjusted step-size is given in Figure 1. Figure 1. Comparison of numerical solution ( red circles) with analytical solution.
  • 4. Lab Assignment In this assignment, you are expected to implement the explicit midpoint and explicit trapezoidal methods. The formulations for the above methods are given in equations 1 and 2, respectively. yk1/2= yk h 2 f tk , yk yk1=ykh f tk1/2, yk1/2 (1) yk1 0 = ykh f tk , yk yk1=yk h 2 f tk , yk f tk1, yk1 0  (2) You will write two separate modules named midp.m and trap.m that use Eq. 2 and set of Eqs. 3, respectively. These modules should be able to replace previous beuler.m module, just by changing its name in the main program. In this lab we will compare the methods we have studied for their accuracy. Start with h = 0.02 and adjust the stepsize with accuracy.m using dtol = 0.01. Then plot and compare angular displacement with the exact solution for Forward Euler, Backward Euler, Midpoint and Trapezoidal methods. Homework Assignment Generate a module for the implicit Trapezoidal method: yk1=yk h 2 f tk , yk f tk1 , yk1 (3) Since the above method is implicit you would need to generate an iterative solution procedure similar to the one we have done for the Backward Euler method. Compare the performance of explicit and implicit trapezoidal methods by plotting and tabulating the exact absolute error with respect to time. We can define the exact absolute error as: Et =∣exact t−approximate t∣ (4) Also compare them in terms of the computational time.