Two variables multiple constraints in calculus.
3 views (last 30 days)
Show older comments
<<se-mathworks-com-matlabcentral-answers-uploaded_files-76159-problem_4_5-jp.ng>>
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
This is how far i've come. I know this problem should be really simple to solve, but i struggle. I have no clue about b, d, e part questions.
1 Comment
Walter Roberson
on 29 Apr 2017
+1. Thank you for specifically saying which parts you are having difficulty with.
Accepted Answer
Will Nitsch
on 3 May 2017
For b):
R1 = (24-3.*linspace(1,10,1000))./8;
R2 = linspace(1,10,1000);
Ctot2 = @(r1,r2) C1(r1)+C2(r2); % I didn't spend too much time on this part but for whatever reason it didn't like 'Ctot = @(r) C1(r(1))+C2(r(2));'
figure
plot3(R1,R2,Ctot2(R1,R2))
I got the same answer as you for part c.
For d, just plug in that constraint for r1, 'r1 = (24-3*r2)/8' and differentiate.
Ctot3 = @(r2) 4+(24-3.*r2)./8+((24-3.*r2)./8).^2+25./(1+exp(-r2+6));
figure
plot(R2,Ctot3(R2))
hold on;
plot(R2(2:end),diff(Ctot3(R2))) % 1st derivative (R2 resized accordingly)
plot(R2(2:end-1),diff(Ctot3(R2),2)) % 2nd derivative (R2 resized accordingly, R2 may be a little off with this indexing but it was for dimensionality)
I'm not sure about part e, but perhaps with this other information you might be able to figure it out easier.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!