Question about function (PLOTING)
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Dear fellows,
I have question about some function which I can not plote.
function d = f (a,b,x)
d(x>0 & x<=a) = 9.2.*x.*a./(3.*a+4.*b-x)
d(x>a & x<=b) = 1.2.*a.*b./x;
d(x>b) = 3*x.^2./(a.*b);
Like you see, function is nothing special.
This function works for single values, but as you know to plot some function it is necessary for x to be array.
And I don't know how to solve these conditions x>b, x>a....
How to compare one single value with array, beacuse I need to compare every element of array x with a or b or 0?
Thank you very much dear fellows for any answer.
Respuestas (1)
Daniel Shub
el 18 de Oct. de 2011
Assuming a and b are scalars and x is a vector ...
d = zeros(size(x));
d(x>0 & x<=a) = 9.2.*x(x>0 & x<=a).*a./(3.*a+4.*b-x(x>0 & x<=a));
d(x>a & x<=b) = 1.2.*a.*b./x(x>a & x<=b);
d(x>b) = 3*x(x>b).^2./(a.*b);
Basically, everywhere there is an x, you need to put the condition.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!