Borrar filtros
Borrar filtros

mutiplication and division of a range of number.

2 visualizaciones (últimos 30 días)
kevin
kevin el 27 de Nov. de 2011
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 comentario
kevin
kevin el 27 de Nov. de 2011
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?

Iniciar sesión para comentar.

Respuestas (2)

Andrei Bobrov
Andrei Bobrov el 27 de Nov. de 2011
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 comentarios
kevin
kevin el 28 de Nov. de 2011
can anyone explain F=@(x)x(:,1)./(x(:,2).*x(:,3)).*tand(x(:,4));?
Andrei Bobrov
Andrei Bobrov el 28 de Nov. de 2011
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.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 28 de Nov. de 2011
(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 comentarios
kevin
kevin el 28 de Nov. de 2011
how would you write out the boundary condition? and the equation it self
Walter Roberson
Walter Roberson el 28 de Nov. de 2011
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)

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by