MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Solution 65581

Submitted on 25 Mar 2012 by Robert Canfield

Correct

270Size
`This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.`

### Test Suite

Test
Code Input and Output
1
Pass

```%% Haftka & Gurdal, Figure 5.7.1 example
f = @(x) 0.5*x;
g = @(x) 2-x;
x0 = 0;
[xmin,fmin,u]=alm(f,g,[],x0) %#ok<*NOPTS>
xcorrect=2;
ucorrect=0.5;
assert(norm(xmin-xcorrect)<1e-3)
assert(abs(fmin-f(xcorrect))<1e-3)
assert(abs(u-ucorrect)<1e-3)
```
```xmin =
2.0000
fmin =
1.0000
u =
0.5000
```
2
Pass

```%% Haftka & Gurdal, Example 5.7.1
f = @(x) x(1).^2 + 10*x(2).^2;
h = @(x) sum(x)-4;
x0 = [0; 0];
[xmin,fmin,~,v]=alm(f,[],h,x0)
xcorrect=[40; 4]/11;
vcorrect=-7.2727;
assert(norm(xmin-xcorrect)<1e-3)
assert(abs(fmin-f(xcorrect))<1e-4)
assert(abs(v-vcorrect)<1e-2)
```
```xmin =
3.6364
0.3637
fmin =
14.5455
v =
-7.2685
```
3
Pass

```%% Vanderplaats, Figure 5-4 example
f = @(x) sum(x);
g = @(x) [x(1) - 2*x(2) - 2
8 - 6*x(1) + x(1).^2 - x(2)];
x0 = [0; 0];
[xmin,fmin,u]=alm(f,g,[],x0)
xcorrect=[2; 0];
ucorrect=[0.2; 0.6];
assert(norm(xmin-xcorrect)<1e-4)
assert(abs(fmin-f(xcorrect))<1e-4)
assert(norm(u-ucorrect)<1e-2)
```
```xmin =
2.0000
0.0000
fmin =
2.0000
u =
0.1995
0.5985
```