Skip to content

Commit c68db1b

Browse files
committed
Clarify that implementation is needed in the .m files
1) eulerMethod.m is not implemented and simply returns the initial values 2) gauss2pt.m is not implemented and simply returns the average value 3) simpsonsRule.m is not implemented and simply returns 0 4) eulerMethodDE.m is not implemented and simply returns the initial values 5) rk4.m is not implemented and returns nothing If you are a faculty member who would like solution implementations for reference, please contact [email protected]
1 parent 1f20ebe commit c68db1b

File tree

5 files changed

+72
-65
lines changed

5 files changed

+72
-65
lines changed

NumericalIntegration/eulerMethod.m

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
function [xApprox,yApprox]=eulerMethod(f,init,n,h)
2-
% The eulerMethod function takes four arguments
3-
% f is a function handle
4-
% init = x0 is the initial value
5-
% h is the step size and
6-
% n is the number of steps to estimate
7-
%
8-
% The function returns an (n+1)x2 matrix of
9-
% estimated (xi,yi) values
10-
11-
% Initialize the output with the initial value
12-
% Initialize the output with the initial value
13-
xApprox = nan(n+1,1);
14-
yApprox = nan(n+1,1);
15-
xApprox(1) = init;
16-
yApprox(1) = f(init);
17-
18-
1+
function [xApprox,yApprox]=eulerMethod(f,init,n,h)
2+
% The eulerMethod function takes four arguments
3+
% f is a function handle
4+
% init = x0 is the initial value
5+
% h is the step size and
6+
% n is the number of steps to estimate
7+
%
8+
% The function returns an (n+1)x2 matrix of
9+
% estimated (xi,yi) values
10+
11+
% Initialize the output with the initial value
12+
% Initialize the output with the initial value
13+
xApprox = nan(n+1,1);
14+
yApprox = nan(n+1,1);
15+
xApprox(1) = init;
16+
yApprox(1) = f(init);
17+
18+
% Fill in the details of the implementation here
19+
1920
end

NumericalIntegration/gauss2pt.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
function Fapprox = gauss2pt(f,a,b)
2-
% gauss2pt takes three arguments
3-
% f is a function handle
4-
% a and b are the bounds of a definite integral
5-
%
6-
% Fapprox returns the Gaussian 2 point approximation of the
7-
% integral from a to b of f(x) dx
8-
9-
10-
Fapprox = f((b+a)/2);
1+
function Fapprox = gauss2pt(f,a,b)
2+
% gauss2pt takes three arguments
3+
% f is a function handle
4+
% a and b are the bounds of a definite integral
5+
%
6+
% Fapprox returns the Gaussian 2 point approximation of the
7+
% integral from a to b of f(x) dx
8+
9+
% Fill in the details of the implementation here so your
10+
% code will return a correct approximation of the area
11+
Fapprox = f((b+a)/2);
1112
end
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
function area = simpsonsRule(f,a,b,n)
2-
% simpsonsRule takes four arguments
3-
% f is a function handle
4-
% a and b are the endpoints of the integral
5-
% n is the number of intervals to use for the approximation
6-
%
7-
% area is the value computed by using a three-point Simpson's rule
8-
% approximation on each subinterval
9-
10-
area = 0;
11-
1+
function area = simpsonsRule(f,a,b,n)
2+
% simpsonsRule takes four arguments
3+
% f is a function handle
4+
% a and b are the endpoints of the integral
5+
% n is the number of intervals to use for the approximation
6+
%
7+
% area is the value computed by using a three-point Simpson's rule
8+
% approximation on each subinterval
9+
10+
% Fill in the details of the implementation here so your
11+
% code will return a correct approximation of the area
12+
area = 0;
13+
1214
end

NumericalODEs/eulerMethodDE.m

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
function [xApprox,yApprox]=eulerMethod(f,init,n,h)
2-
% The eulerMethod function takes four arguments
3-
% f is a function handle
4-
% init = [x0 f(x0)] is the initial condition
5-
% h is the step size and
6-
% n is the number of steps to estimate
7-
%
8-
% The function returns an (n+1)x2 matrix of
9-
% estimated (xi,yi) values
10-
11-
% Initialize the output with the initial value
12-
% Initialize the output with the initial value
13-
xApprox = nan(n+1,1);
14-
yApprox = nan(n+1,1);
15-
xApprox(1) = init(1);
16-
yApprox(1) = init(2);
17-
18-
1+
function [xApprox,yApprox]=eulerMethodDE(f,init,n,h)
2+
% The eulerMethodDE function takes four arguments
3+
% f is a function handle
4+
% init = [x0 f(x0)] is the initial condition
5+
% h is the step size and
6+
% n is the number of steps to estimate
7+
%
8+
% The function returns an (n+1)x2 matrix of
9+
% estimated (xi,yi) values
10+
11+
% Initialize the output with the initial value
12+
% Initialize the output with the initial value
13+
xApprox = nan(n+1,1);
14+
yApprox = nan(n+1,1);
15+
xApprox(1) = init(1);
16+
yApprox(1) = init(2);
17+
18+
% Fill in the details of the implementation here
19+
20+
1921
end

NumericalODEs/rk4.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
function [t,y] = rk4(f,tspan,y0,n)
2-
% rk4 implements a four-step Runge-Kutta method on function f
3-
% over t = tspan(1) to t = tspan(2) where y(tspan(1))=y0
4-
% using n intervals
5-
%
6-
% t is a vector of t values and y is a vector of estimated y(t) values
7-
8-
1+
function [t,y] = rk4(f,tspan,y0,n)
2+
% rk4 implements a four-step Runge-Kutta method on function f
3+
% over t = tspan(1) to t = tspan(2) where y(tspan(1))=y0
4+
% using n intervals
5+
%
6+
% t is a vector of t values and y is a vector of estimated y(t) values
7+
8+
% Fill in the details of the implementation here
9+
910
end

0 commit comments

Comments
 (0)