필터 지우기
필터 지우기

mutiplication and division of a range of number.

조회 수: 2 (최근 30일)
kevin
kevin 2011년 11월 27일
it seem my previously question has been worded badly, so i will try again.
let say a b and c is a number from 1 to 10, d is a number from 5 to 20.
so F=(a/(b*c))*tan(d) <---not in matlab format
and i trying to find what a b c and d is when F=max.i tried alot of different way to do it, but it all return with matrix error.
  댓글 수: 1
kevin
kevin 2011년 11월 27일
for example
a=[1:1:3] % Row vector using your strange syntax.
b=[3:1:5] % Another row vector.
c1 = a' * b % Note transpose operator '
a =
1 2 3
b =
3 4 5
c1 =
3 4 5
6 8 10
9 12 15
this is fin when when a and b is a 1x3 vector, but what do you do when a=1 2 3 4 and b =2 3 4 5 6 7 8?

댓글을 달려면 로그인하십시오.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2011년 11월 27일
variant 1
F=@(x)-x(1)/(x(2)*x(3))*tand(x(4))
out = fmincon(F,[1 1 1 5],[],[],[],[],[1 1 1 5],[10 10 10 20],[],optimset('Algorithm','active-set'))
variant 2
[a b c d] = ndgrid(1:10,1:10,1:10,5:20);
v = [a(:),b(:),c(:),d(:)];
F=@(x)x(:,1)./(x(:,2).*x(:,3)).*tand(x(:,4));
out1 = F([a(:),b(:),c(:),d(:)]);
[n,n] = max(out1);
out2 = v(n,:);
  댓글 수: 3
kevin
kevin 2011년 11월 28일
can anyone explain F=@(x)x(:,1)./(x(:,2).*x(:,3)).*tand(x(:,4));?
Andrei Bobrov
Andrei Bobrov 2011년 11월 28일
Hi Kevin! Please read:
1. http://www.mathworks.com/help/techdoc/ref/specialcharacters.html
2. http://www.mathworks.com/help/techdoc/ref/arithmeticoperators.html
3. http://www.mathworks.com/help/techdoc/ref/function_handle.html
4. http://www.mathworks.com/help/techdoc/ref/tand.html
Use in your works MATLAB help.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 11월 28일
(a/(b*c))*tan(d) would be maximum when abs(a) is maximum, abs(b*c) is minimum, and abs(tan(d)) is maximum.
As you know the ranges of the variables and know the sign of them is consistent, you can just plug in the appropriate boundary conditions: maximum a, minimum b and c, maximum d, so that would be a=10, b=1, c=1, d=20, which would give 10/(1*1) * tand(20) which is 10*tand(20), which is a value that is approximately 3.64 .
  댓글 수: 2
kevin
kevin 2011년 11월 28일
how would you write out the boundary condition? and the equation it self
Walter Roberson
Walter Roberson 2011년 11월 28일
ab = max(a);
bb = min(b);
cb = min(c);
db = max(d);
out = (ab / (bb*cb))*tand(db);
More generally,
[A,B,C,D] = ndgrid([min(a),max(a)], [min(b),max(b)], [min(c),max(c)], [min(d),max(d)]);
out1 = A./(B.*C).*tand(D);
[maxval, idx] = max(out1(:));
fprintf(1,'maximum value was: %g at (%g,%g,%g,%g)\n', maxval, A(idx), B(idx), C(idx), D(idx));
This simple coding cannot be used if any of the subexpressions do not change monotonically over the permitted ranges of the variables. For example it could not be used if any of the subexpressions could lead to a division by 0, or if there was a subexpression of the form (x-3)^2 when x ranged below and above 3 (because the result would decrease to a minimum and then increase again)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by