Need help regarding optimization

Hi, here's the operation I want to do
1. the following operations:
A=rand(10,2)*100;
B=rand(10,2)*100;
c=[ones(10,1)*80.5 ones(10,1)*89.27];
result=A-B;
result(~(A-c>=0)) = 0
2. the following optimization (wich i don't know how to do exept with a looop but I want something faster and more straight forward)
I want to do the sum of the variable"results" and get the maximum.In this case the result would be in the form of: 1x2
So clearly I want to find the "c" that maximise "result2":
result2=sum(result)
(in the previous example the "c" were 80.5 and 89.27
So the point is when we do
result=A-B;
result(~(A-c>=0)) = 0
Some "A-B" yield a negative results so I want to find the c that
optimize positively. Let's set the "c" as c1 and c2
the final optization is going to be in the following dimesnion:
c=[ones(4,1)*c1 ones(4,1)*c2];
Thank you in advance
Gimpy

7 件のコメント

Gimpy
Gimpy 2012 年 8 月 15 日
Let's take the following example (4x1, but I'am going to have something like 22000x18)
If IF A >= C then A-B
example: A=[45;37;32;50]
B=[17;100;200;10]
The alwser would be 45.00 or something between 45.0=<C>37
45.0 would be a good (I don't need an interval)
Gimpy
Gimpy 2012 年 8 月 15 日
In this case the maximun of A-B is 68 if 45.0=<C>37
Matt Fig
Matt Fig 2012 年 8 月 15 日
編集済み: Matt Fig 2012 年 8 月 15 日
Please take the time to give just one good example that captures all of the salient features of your real problem. If you have 22000-by-18, make a specific example with 5(or 6,7 or 8)-by-3. Show exactly (give the numeric arrays) the inputs and the exact expected output(s) for your specific example.
Thanks.
Gimpy
Gimpy 2012 年 8 月 15 日
編集済み: Walter Roberson 2012 年 8 月 15 日
ok here's my example again:
A=[45;37;32;50]
B=[17;100;200;10]
c=??(the value we look for)
The condition to test:
A=[45;37;32;50]
B=[17;100;200;10]
c=? (the value we are looking for)
the condition to test:
A >= C then A-B, else A-B=0
in my example the C we look for is something between 37.01 and 50 because.
In excel for example to be more specific:
cells A2= 45,A3=37,A4=32,A5=50
B2=17, B3=100, B4=200, B5=10
C2:C5=37.01 (in this case i know the results by trial and error).
The condition to test is:
=IF(A2>=C2,(A2-B2),0)= 28
=IF(A3>=C3,(A3-B3),0)=0
=IF(A4>=C4,(A4-B4),0)=0
=IF(A5>=C5,(A5-B5),0)=40
Total: 68
Any value between 37.01 and 50 would give the save result. A way to find the lower and uper bound would be appreciate of only one...
Thanks again for your patience and help.
Matt Fig
Matt Fig 2012 年 8 月 15 日
Where did the values of 37.1 and 50 come from?
Inputs --- A=[45;37;32;50], B=[17;100;200;10]
Outputs --- C = [37.01 50]
Is this correct? If so, please show the MATLAB for loop you say you have that gets this result.
Gimpy
Gimpy 2012 年 8 月 15 日
編集済み: Gimpy 2012 年 8 月 15 日
the value the values of 37.1 and 50 come from trial and error in Excel by testing:
=IF(A2>=C2,(A2-B2),0)= 28
=IF(A3>=C3,(A3-B3),0)=0
=IF(A4>=C4,(A4-B4),0)=0
=IF(A5>=C5,(A5-B5),0)=40
In this case it's the result we are looking for.
Gimpy
Gimpy 2012 年 8 月 15 日
Here’s my problem with more explanation again:
Matrix A,B,C :22 500 x18
Matrix c : each colum are scalar
Exemple :[50;50;50;50 72.25;72.25;72.25;72.25]
… Here’s what I want to do :
For each elements in A, lets call them ai, if ai >ci then
ai - bi
else
ai - bi =0
Here’s what I do in matlab(for simplification I do a 4x1)
a1=[88;57;42;100];
a2=[98;87;32;80];
A=[a1 a2];
b1=[78;5;32;106];
b2=[88;87;35;88];
B=[b1 b2];
c=[ones(4,1)*80.5 ones(4,1)*89.27];
result=A-B;
result(~(A-c>=0)) = 0
result2=sum(result)
****Now here’s the point : I want to find the matrix c that’s going to maximise :
result2=sum(result).
The results should be an interval
In the revious example I’am expecting MATLAB to give something like:
resultat2= 68
C_lower= 37
C_upper=45
Or at least one one of the 2 results (37 or 45).
I found this result by calculating result2=sum(result) by trial and error until
I get the maximum value(result2=68).
Please keep I mind that I want to work with 22500x18

回答 (0 件)

この質問は閉じられています。

製品

質問済み:

2012 年 8 月 15 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by