Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# 02_roots_and_optimization
Repository for homework 2
Question 2
```matlab
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,fx,ea,iter]=falsepos(cat_cable,900,910,0.00001)
```
```matlab
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,fx,ea,iter]=bisect(cat_cable,908,909,0.00001)
```
```matlab
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,ea,iter]=mod_secant(cat_cable,900,910,0.00001)
```
```matlab
| solver | initial guess | ea | number of iterations|
| --- | --- | --- | --- |
|falsepos | 900, 910 | 0.00001| 4 |
|mod_secant | 900, 910 | 0.00001| 50 |
|bisect | 900, 910 | 0.00001| 17 |
```
![Powerline Plot](./problem1c.png)
Question 3
```matlab
f = @(x) (x-1)*exp(-(x-1)^2);
df = @(x) -(2*(x)^2-4*x+1)*exp(-(x-1)^2);
[root,ea,iter]=newtraph(f,df,3,.00001,5)
```
```matlab
### divergence of Newton-Raphson method
| iteration | x_i | approx error |
| --- | --- | --- |
| 0 | 3 | n/a |
| 1 | 3 | 8.6957 |
| 2 | 3 | 6.8573 |
| 3 | 3 | 5.7348 |
| 4 | 3 | 4.9605 |
| 5 | 3 | 4.3873 |
```
```matlab
### convergence of Newton-Raphson method
| iteration | x_i | approx error |
| --- | --- | --- |
| 0 | 1.2 | n/a |
| 1 | 1.2 | 22.1239 |
| 2 | 1.2 | 1.7402 |
| 3 | 1.2 | 0.0011 |
| 4 | 1.2 | 2.3315e-13 |
| 5 | 1.2 | 2.3315e-13 |
```
Question 4
a)
```matlab
lj = @(x) 4*0.039*((2.394./x).^12-(2.394./x).^6);
[x,E,ea,its] = goldmin(lj,0,3)
```
```matlab
x = 2.6872
E = -0.0390
ea = 9.7092e-05
its = 27
```
b)
```matlab
F = (0:0.0022/30:.0022)
lj = @(x) 4*0.039*((2.394./x).^12-(2.394./x).^6);
ET = @(dx) lj(dx)*(2.6872+dx)- F*dx;
[x,fx,ea,iter]=goldmin(ET,0,1)
```
```matlab
x = 1.0000
fx = 1.0e+04
ea = 8.6968e-05
iter = 27
```
c)
```matlab
function SSE = sse_of_parabola(K,xdata,ydata)
% calculate the sum of squares error for a parabola given a function, func, and xdata and ydata
% output is SSE=sum of squares error
K1=K(1);
K2=K(2);
y_function = K1*xdata+1/2*K2*xdata.^2;
SSE = sum((ydata-y_function).^2);
end
```
d)
```matlab
dx = zeros(1,50); % [in nm]
F_applied=linspace(0,0.0022,50)
[K,SSE_min]=fminsearch(@(K) sse_of_parabola(K,dx,F_applied),[1,1])
```
```matlab
K = 1 1
SSE_min = 8.1490e-05
```
e)