Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
problem 3 started
  • Loading branch information
nin13001 committed Dec 6, 2017
1 parent 0908032 commit ad5e7ed
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -47,3 +47,23 @@ y(1)=y0;
end
```
![](assets/README-23f54e97.png)

# Problem 3
## Part A
The analytical solution is y = cos(3t)

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

0 comments on commit ad5e7ed

Please sign in to comment.