Professional Documents
Culture Documents
ECH 3854
Jose Mariano da Silva Neto
QUESTION #1 - Use the Newton's method optimization code you developed in class to solve
Problem 7.27 (page 201 -202) in the text by Steven C. Chapra. Plot the solution (obtained at each
iteration) as a function of iteration number. Use MATLAB built-in function to compute the
solution to the problem and compare the result obtained from your code with MATLAB's built in
code (use format long for both solutions).
SOLUTION:
From the results obtained, we can see that for this problem we have a total of 3 iterations. For
each iteration we have a value for the conversion. Thus, it was possible to plot the solution as a
function of iteration number:
Now, using the MATLAB's built in code we can find that the conversion that will result in the
lowest cost system will be:
>> f = @(x)((1/(1-x)^2)^0.6 + 6*(1/x)^0.6);
>> [z,g]=fminbnd(f,0,1)
z =
0.587699429667029
g =
11.149510226378936
And from my code I obtained:
root =
0.587683281274433
fval =
11.149510217523581
We can calculate the absolute error for the difference between the obtained values:
| |
MATLAB CODE
% NEWTON'S METHOD
clear; clc; %Clear command window
disp ('---- Newtons Method ----')
xest = input('\n Initial guess = ');
[root fval iter] = newton_prob(@newton_model, xest)
% Model for the problem
function [df1, df2] = newton_model(x)
df1 = (6/(5*(1-x)^(11/5)) - 18/(5*x^(8/5))); % This is the first derivative
%of the objective function.
df2 =(144/(25*x^(13/5)) + 66/(25*(1-x)^(16/5)));% This is the second
derivative %of the objective function.
% NEWTON'S METHOD
function [root, fval, iter] = newton_prob(func, x0)
tol = 1e-3; % This is the tolerance
itmax = 50; % This is the maximum number of iterations
iter = 1;
xold = x0;
[df1 df2] = func(xold);
xnew = xold - df1/df2;
while abs(xnew-xold) > tol
iter = iter + 1;
if iter > itmax
disp (' ')
disp ('Root not found')
break
end
xold = xnew;
[df1 df2] = func(xold);
xnew = xold - df1/df2;
end
format long
root = xnew;
fval= ((1/(1-xnew)^2)^(0.6) + 6*(1/xnew)^0.6);
QUESTION #2 - Write a simple function using built-in MATLAB function for
multidimensional optimization to solve problem 7.30 in Chapra's book. Include your program
with your final solution in your submitted work.
SOLUTION:
The two-dimensional distribution of pollutant concentration in a channel can be described by:
( )
To minimize the function above, we can rewrite as:
(
Now, the MATLAB has a function fminsearch that can be used to determine the minimum of a
multidimensional function. So, we can use this function to solve the problem. However, the
question asks to calculate the exact location of the peak concentration that is the maximum. In
this case its necessary inverting the signs of the function:
(
Using the MATLAB it was possible to find the answer:
MATLAB CODE
> f =@(x)-7.9-0.13*x(1)-0.21*x(2)+0.05*x(1)^2+0.016*x(2)^2+0.007*x(1)*x(2);
[x,fval]=fminsearch(f,[-10,20])
x =
0.8537 6.3757
fval =
-8.6249