mutiplication and division of a range of number.
Mostrar comentarios más antiguos
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
el 27 de Nov. de 2011
Respuestas (2)
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
el 27 de Nov. de 2011
kevin
el 28 de Nov. de 2011
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.
Walter Roberson
el 28 de Nov. de 2011
0 votos
(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
el 28 de Nov. de 2011
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)
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!