Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
problem 2 part B
  • Loading branch information
nin13001 committed Dec 6, 2017
1 parent 40a7ed0 commit fdd7e99
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
@@ -1,4 +1,21 @@
# 06_initial_value_ode
# Problem 2
## Part A
The analytical solution to y' = -y is y = e^-t
The analytical solution to y' = -y is y = e^-t

## Part B

```
dt=[0.5 .1 .001];
figure();
hold on
x=[0:dt(2):3]';
y_n=zeros(size(x));
y_n(1)=1;
for i=2:length(x)
dy=prob2_ode(x,y_n(i-1));
y_n(i)=y_n(i-1)+ dt(2)*dy;
end
plot(x,exp(-x),'k-',x,y_n,'o');
```
![](assets/README-66741291.png)
Binary file added assets/README-66741291.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions prob2_ode.m
@@ -0,0 +1,3 @@
function dy= prob2_ode(t,y)
dy=-y;
end
11 changes: 11 additions & 0 deletions prob2ptB.m
@@ -0,0 +1,11 @@
dt=[0.5 .1 .001];
figure();
hold on
x=[0:dt(2):3]';
y_n=zeros(size(x));
y_n(1)=1;
for i=2:length(x)
dy=prob2_ode(x,y_n(i-1));
y_n(i)=y_n(i-1)+ dt(2)*dy;
end
plot(x,exp(-x),'k-',x,y_n,'o');

0 comments on commit fdd7e99

Please sign in to comment.