Calculus Matlab two variables

2 次查看(过去 30 天)
Ema
Ema 2017-4-25
编辑: Ema 2017-4-29
% 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 个评论
Ema
Ema 2017-4-25
Ive done that but dont really understand how i would put that into my code and make the problemsolving to work

请先登录,再进行评论。

回答(1 个)

xi
xi 2017-4-25
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 个评论
Ema
Ema 2017-4-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by