AMATH 301 Lecture Notes - Lecture 23: Matlab

74 views3 pages
2 Mar 2018
School
Course

Document Summary

Lecture 23 notes clear all; close all; clc. % x"" = 0, x(0) = x0, x(t) = xt x0 = 1; xt = 5; t = 2; dt = 0. 1; N = t/dt; % number of interior points = n-1 t = 0:dt:t; % most convenient way to create the matrix v2 = -2*ones(n-1,1); v1 = ones(n-2, 1); % x"" + x = 0, x(0) = x0, x(t) = xt x0 = 0; xt = 5; t = 2; dt = 0. 01; t = 0:dt:t; N = t/dt; % interior points = n-1 v2 = -2*ones(n-1,1); v1 = ones(n-2, 1); A = diag(v2) + diag(v1, 1) + diag(v1, -1); = zeros(n-1, 1); b(1) = -x0/dt^2; b(end) = -xt / dt^2; x_interiors = a\b; x = [x0; x_interiors; xt]; x_true = ((xt / sin(t))) * sin(t"); plot(t, x_true, "k", t, x, "r"); error = norm(x - x_true, inf);

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related textbook solutions

Related Documents