Question about function (PLOTING)

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.

Answers (1)

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.

This question is closed.

Tags

Asked:

on 18 Oct 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!