optimisation of simple equation

let say a=1:1:10 b=1:1:20 c:1:1:15 and the equation is:
k= (a/b)*cos(c)
and i need to get the value of a b and c when k is min or max, how do you do it?
thx

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 14 de Oct. de 2011
% determination of all combinations of values of the vectors a,b,c -> [a(:) b(:) c(:)]
[a b c] = meshgrid(1:10,1:20,1:15 );
% definition of all possible values of 'k'
k = a(:)./b(:).*cos(c(:));
% min and max values of 'k', [i1,i2] - indexes of the min and max values
[v1,i1] = max(k);
[v2,i2] = min(k);
% first row of the 'out' values of the 'a','b' and 'c' when 'k' -max, second - 'k' - min
out = [a(i1) b(i1) c(i1);a(i2) b(i2) c(i2)]

5 comentarios

kevin
kevin el 16 de Oct. de 2011
thanks for the answer, but can you write a short sentence which say what each line do?
kevin
kevin el 27 de Nov. de 2011
how would you do the same with four variable? i get
??? Error: File: The_Crane_Design.m Line: 10 Column: 49
Unbalanced or unexpected parenthesis or bracket.
when i try more than 3
Sven
Sven el 27 de Nov. de 2011
"Unbalanced or unexpected parenthesis or bracket" means that the code you have has a small typo... a missing parenthesis or bracket.
kevin
kevin el 27 de Nov. de 2011
i wrote
[a b r t p] = meshgrid(1:0.1:4,1:0.1:4,1.2:0.1:2.2,-20:0.5:80,0:0.5:90);
do you see any error?
kevin
kevin el 27 de Nov. de 2011
i am think i got error for it was because meshgrid only support 3 varibles ie 3d

La pregunta está cerrada.

Preguntada:

el 14 de Oct. de 2011

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by