MAT 275 Matlab Assignment 3 - MAT 275 Vaz Online%MAT 275...

This preview shows page 1 - 3 out of 7 pages.

MAT 275 – Vaz – Online %%MAT 275 Matlab Assignment #3 %Exercise 1 clear all clc close all % Part A f=inline('2*y','t','y'); t = linspace(0,.5,100); y = 3*exp(2*t); % evaluate the exact solution %Euler Approx. [t5,y5] = euler(f,[0,.5],3,5); % use @f if defined in separate function [t50,y50] = euler(f,[0,.5],3,50); [t500,y500] = euler(f,[0,.5],3,500); [t5000,y5000] = euler(f,[0,.5],3,5000); e5=y(end)-y5(end); %error with N=5 e50=y(end)-y50(end); e500=y(end)-y500(end); e5000=y(end)-y5000(end); ratio50=e5/e50; ratio500=e50/e500; ratio5000=e500/e5000; N5 = y5(end); N50 = y50(end); N500 = y500(end); N5000 = y5000(end); Euler’s Method Table N Approximation Error Ratio 5 7.4650 0.6899 N/A 50 8.0748 0.0801 8.6148 500 8.1467 0.0081 9.83381 5000 8.1540 8.1534e-04 9.9835 % Part B %For every step taken in the Euler's method %the size is reduced by 10, the error ratio %is also decreases the error ratio by 10, %proving that the order of the function is %first order %Part C %Euler's method underestimates the actual curve %because the concavity of the function is facing %upwards, so Euler's will always under estimate
MAT 275 – Vaz – Online %% Exercise 2 % Part A t = 0:.45:10; y = -30:6:42 ; % define grid of values in t and y direction [T,Y]=meshgrid(t,y); % creates 2d matrices of points in the ty-plane

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture