Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mjb13028 committed Dec 5, 2017
1 parent bfe5886 commit f330735
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 49 deletions.
5 changes: 2 additions & 3 deletions HW6Problem2.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
set(0, 'defaultAxesFontsize', 16)
set(0, 'defaultTextFontsize', 16)
set(0, 'defaultLineLineWidth', 2)
hold on
t = [0:dt:3]';
y_n = zeros(size(t));
y_n(1) = 1; %initial condition
Expand All @@ -18,12 +17,12 @@
plot(t, y_analytical(t), 'k-', t, y_n, 'o-');
title('Analytical vs. Euler')
legend('Analytical', 'Euler', 'Location', 'Northeast')
saveas(a, 'euler.png');
saveas(a, 'euler2.png');

%Part c.
b = figure(2);
y_heun = heun_sol_order1(@(t,y) ode2(t,y), dt, 1, [0 3]);
plot(t, y_analytical(t), 'k-', t, y_heun, 'o-');
title('Analytical vs. Heun')
legend('Analytical', 'Heun', 'Location', 'Northeast')
saveas(b, 'heun.png');
saveas(b, 'heun2.png');
27 changes: 0 additions & 27 deletions HW6Problem2.m~

This file was deleted.

39 changes: 23 additions & 16 deletions HW6Problem3.m
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
%Part b.
dy = ode3(0, [1;0]);
dt = [0.1 0.01 0.001];
figure()
hold on
for k = 1:length(dt)
t = [0:dt(k):3]';
y_n = zeros(length(t), 2);
y_n(1, :) = [1 0]; %initial condition
for i = 2:length(t)
dy = ode3(t, y_n(i-1, :));
y_n(i, :) = y_n(i-1, :) + dt(k)*dy;
end
%Part a.
y_analytical = @(t) cos(3*t);

plot(t, cos(3*t), 'k-', t, y_n(:,1), 'o-');
%Part b.
dt = 0.001; %step size
a = figure(1);
set(0, 'defaultAxesFontsize', 16)
set(0, 'defaultTextFontsize', 16)
set(0, 'defaultLineLineWidth', 2)
t = [0:dt:3]';
y_n = zeros(length(t), 2);
y_n(1, :) = [1 0]; %initial condition
for i = 2:length(t)
dy = ode3(t, y_n(i-1, :));
y_n(i, :) = y_n(i-1, :) + dt(k)*dy;
end
plot(t, y_analytical(t), 'k-', t, y_n(:,1), 'o-');
title('Analytical vs. Euler')
legend('Analytical', 'Euler', 'Location', 'Northeast')
saveas(a, 'euler3.png');

%Part c.
figure()
b = figure(2);
dt = 0.001;
t = [0:dt:3];
y_heun = heun_sol_order2(@(t,y) ode3(t,y), dt, [1 0], [0 3]);
plot(t, cos(3*t), 'k-', t, y_heun(:,1), 'o-');
plot(t, y_analytical(t), 'k-', t, y_heun(:,1), 'o-');
title('Analytical vs. Heun')
legend('Analytical', 'Heun', 'Location', 'Northeast')
saveas(b, 'heun3.png');
26 changes: 26 additions & 0 deletions HW6Problem3.m~
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%Part a.
y_analytical = @(t) cos(3*t);

%Part b.
dt = 0.01; %step size
a = figure(1);
set(0, 'defaultAxesFontsize', 16)
set(0, 'defaultTextFontsize', 16)
set(0, 'defaultLineLineWidth', 2)
t = [0:dt:3]';
y_n = zeros(length(t), 2);
y_n(1, :) = [1 0]; %initial condition
for i = 2:length(t)
dy = ode3(t, y_n(i-1, :));
y_n(i, :) = y_n(i-1, :) + dt(k)*dy;
end

plot(t, cos(3*t), 'k-', t, y_n(:,1), 'o-');
end

%Part c.
figure()
dt = 0.001;
t = [0:dt:3];
y_heun = heun_sol_order2(@(t,y) ode3(t,y), dt, [1 0], [0 3]);
plot(t, cos(3*t), 'k-', t, y_heun(:,1), 'o-');
52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ a = figure(1);
set(0, 'defaultAxesFontsize', 16)
set(0, 'defaultTextFontsize', 16)
set(0, 'defaultLineLineWidth', 2)
hold on
t = [0:dt:3]';
y_n = zeros(size(t));
y_n(1) = 1; %initial condition
Expand All @@ -35,5 +34,52 @@ legend('Analytical', 'Heun', 'Location', 'Northeast')
saveas(b, 'heun.png');
```

### Part a.
![Analytical vs. Euler](./euler.png)
### Part b.
![Analytical vs. Euler](./euler2.png)

### Part c.
![Analytical vs. Heun](./heun2.png)

## Problem 3

### Script:
```matlab
%Part a.
y_analytical = @(t) cos(3*t);
%Part b.
dt = 0.001; %step size
a = figure(1);
set(0, 'defaultAxesFontsize', 16)
set(0, 'defaultTextFontsize', 16)
set(0, 'defaultLineLineWidth', 2)
t = [0:dt:3]';
y_n = zeros(length(t), 2);
y_n(1, :) = [1 0]; %initial condition
for i = 2:length(t)
dy = ode3(t, y_n(i-1, :));
y_n(i, :) = y_n(i-1, :) + dt(k)*dy;
end
plot(t, y_analytical(t), 'k-', t, y_n(:,1), 'o-');
title('Analytical vs. Euler')
legend('Analytical', 'Euler', 'Location', 'Northeast')
saveas(a, 'euler3.png');
%Part c.
b = figure(2);
dt = 0.001;
t = [0:dt:3];
y_heun = heun_sol_order2(@(t,y) ode3(t,y), dt, [1 0], [0 3]);
plot(t, y_analytical(t), 'k-', t, y_heun(:,1), 'o-');
title('Analytical vs. Heun')
legend('Analytical', 'Heun', 'Location', 'Northeast')
saveas(b, 'heun3.png');
```

### Part b.
![Analytical vs. Euler](./euler3.png)

### Part c.
![Analytical vs. Heun](./heun3.png)

## Problem 4
Binary file removed euler.png
Binary file not shown.
Binary file added euler3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed heun.png
Binary file not shown.
Binary file added heun3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f330735

Please sign in to comment.