MATLAB Answers

Calculus Matlab two variables

2 views (last 30 days)
Ema
Ema on 25 Apr 2017
Edited: Ema on 29 Apr 2017
% code
clear all
a) -------------------------
r1 = linspace (1,4);
r2 = linspace (1,10);
c1 = 4 + r1 + r1.^2
c2 = 25./(1+(exp(1)).^(-r2+6))
ctot = c1 + c2
plot (ctot)
b) -------------------------
r1 = linspace (1,4);
r2 = linspace (1,10);
c1 = 4 + r1 + r1.^2
c2 = 25./(1+(exp(1)).^(-r2+6))
ctot = c1 + c2
plot3(c1,c2,ctot)
hold on
z = 8.*r1+3.*r2-24
r_1 = 8.*r1
r_2 = 3.*r2
z = linspace (24,24);
plot3 (r_1,r_2,z)
end
This is how far ive come. I know this problem should be really simple to solve, but i struggle. I have no clue about c,d,e part questions.

  2 Comments

Ema
Ema on 25 Apr 2017
Ive done that but dont really understand how i would put that into my code and make the problemsolving to work

Sign in to comment.

Answers (1)

xi
xi on 25 Apr 2017
Try this, using fmincon(), to solve the min problem
x0=[1,1]; Aeq=[8,3]; beq=24; lb=[1,1]; ub=[4,10];
fun=@(x)4+x(1)+x(2)^2+25/(1+exp(-x(2)+6)); [x val] = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);

  1 Comment

Ema
Ema on 26 Apr 2017
Thank you. I guess you ment x(1)^2 and not x(2)^2. Ive got the x and val now. But i just have an hard time to specify the answers with code to all the steps.
I should do a small report for each step, ie a,b,c,d,e.
if true
clear all
a) -------------------------
r1 = linspace (1,4);
r2 = linspace (1,10);
C1 = 4+r1+r1.^2
C2 = 25./(1+(exp(1)).^(-r2+6))
Ctot = C1 + C2
plot(Ctot)
b) -------------------------
Dont know how to plot (Ctot) alongs the constraint 8r1+3r2=24
c) -------------------------
Think i got this one right
r0=[1,1];
Aeq=[8,3];
beq=24;
lb=[1,1];
ub=[4,10];
fun=@(r)4+r(1)+r(1)^2+25/(1+exp(-r(2)+6));
[r fval,EXITFLAG , OUTPUT] = fmincon(fun,r0,[],[],Aeq,beq,lb,ub);
X = fminsearch (fun, r0)
d)-------------------------
Struggling abit with this one.
i know that i can calculate second derivative with diff(Ctot,2)
but dont know how to calcualte dCtot/dr(2)
e)-------------------------
I know how to calculate gradient with grad(Ctot = gradient(Ctot)
but dont know how to calculate the gradient of the constraint in solvingpoint.
r
fval
OUTPUT.message
end
Would be really glad if i could get some more help from you. Maybe not an whole answer if you are busy. But atleast a bit more of your guidelines.

Sign in to comment.


Translated by