For question one utilize provided code in matlab: function [x0,lambda,y]=main(x0,lambda,y,mu) if nargin<4 x0=[40;40;

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

For question one utilize provided code in matlab: function [x0,lambda,y]=main(x0,lambda,y,mu) if nargin<4 x0=[40;40;

Post by answerhappygod »

For question one utilize provided code in matlab:
For Question One Utilize Provided Code In Matlab Function X0 Lambda Y Main X0 Lambda Y Mu If Nargin 4 X0 40 40 1
For Question One Utilize Provided Code In Matlab Function X0 Lambda Y Main X0 Lambda Y Mu If Nargin 4 X0 40 40 1 (75.6 KiB) Viewed 38 times
function [x0,lambda,y]=main(x0,lambda,y,mu)
if nargin<4
x0=[40;40;40;-40];
lambda=[0;0];
y=[0;0];
mu=200;
end
format compact
Ae=[1,1,1,1;-1,1,1,1];
be=[2;3];
Ai=[1,-1,1,1;1,1,-1,1];
bi=[1;4];
f=@(x) norm(x)^2
%x0=[40;40;40;-40]
h=@(x) Ae*x-be;
g=@(x) Ai*x-bi;
%mu=200;
s=-g(x0)
%lambda=[0;0];
%y=[0;0];
for k=1:400
[A,B]=fullsystem(f,g,h,x0,s,lambda,y,mu);
ds=-A\B;
x0=x0+ds(1:4);
s=s+inv(diag(s))*ds(5:6);
y=y+ds(7:8);
lambda=lambda+ds(9:10);
R=norm(ds([1:4]));
if R<1e-5
break
end
end
x0
Ae*x0-be
s
end
function [A,B]=fullsystem(f,g,h,x,s,lambda,y,mu)
H=Hessian(f,g,h,x,lambda,y);
Jg=Jacobiang(g,x);
Jh=Jacobianh(h,x);
nx=length(x);
ng=length(s);
nh=length(h(x));
A=[H,zeros(nx,ng),Jh' ,Jg' ;zeros(ng,nx),
diag(s)*diag(lambda),zeros(ng,nh),diag(s);Jh,zeros(nh,2*ng+nh);Jg,diag(s),zeros(ng,nh+ng)];

B=[gradientf(f,x)+Jh'*y+Jg'*lambda;diag(s)*lambda-mu*ones(ng,1);h(x);g(x)+s];

end
function gf=gradientf(f,x)
dx=1e-5;
gf=zeros(length(x),1);
for j=1:length(x)
dxj=0*x;
dxj(j)=dx;
gf(j)=(f(x+dxj)-f(x))/dx;
end
end
function H=Hessian(f,g,h,x,lambda,y)
dx=1e-5;
H=zeros(length(x),length(x));
for j=1:length(x)
dxj=0*x;
dxj(j)=dx;
dfj= @(x) (f(x+dxj)-f(x))/dx;
for k=j:length(x)
dxk=0*x;
dxk(k)=dx;
H(j,k)=(dfj(x+dxk)-dfj(x))/dx;
H(k,j)=H(j,k);
end
end
G=zeros(length(x),length(x));
for j=1:length(x)
dxj=0*x;
dxj(j)=dx;
dgj=@(x) (g(x+dxj)-g(x))/dx;
for k=j:length(x)
dxk=0*x;
dxk(k)=dx;
ddgjk=(dgj(x+dxk)-dgj(x))/dx;
G(j,k)=sum(ddgjk.*lambda);
G(k,j)=G(j,k);
end
end
Y=zeros(length(x),length(x));
for j=1:length(x)
dxj=0*x;
dxj(j)=dx;
dhj=@(x) (h(x+dxj)-h(x))/dx;
for k=j:length(x)
dxk=0*x;
dxk(k)=dx;
ddhjk=(dhj(x+dxk)-dhj(x))/dx;
Y(j,k)=sum(ddhjk.*y);
Y(k,j)=Y(j,k);
end
end
H=H+G+Y;
end
function Jg=Jacobiang(g,x)
dx=1e-5;
Jg=zeros(length(g(x)),length(x));
for j=1:length(x)
dxj=0*x;
dxj(j)=dx;
Jg(:,j)=(g(x+dxj)-g(x))/dx;
end
end
function Jh=Jacobianh(h,x)
dx=1e-5;
Jh=zeros(length(h(x)),length(x));
for j=1:length(x)
dxj=0*x;
dxj(j)=dx;
Jh(:,j)=(h(x+dxj)-h(x))/dx;
end
end
1. Using fmincon or similar solver, solve the following optimization problem (Provide all code and your solutions) min pix} + P2x+ P3xz s.t. P1 > 0, P2 > 0, P3 > 0, P1 + p2 + P3 = 5, 21 > 202 +4, X1 + x3 > X2 + 2 2. RMData.csv is a file that contains 135 different simulated return signals from 15 different geometries (the signal arrived at 9 different angles for each geometry). B.csv is a file that contains the list of the 135 geometries. Using an unconstrained minimization solver, formulate a logistic regression prediction algorithm that will correctly distinguish the first geometry from all the others. Repeat the process for the other 14 geometries and for each one report the accuracies you can obtain (true positives, false positives, false negatives, and true negatives). This will be demonstrated in class for the first geometry on 5/2/2022.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply