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.
0 个评论
回答(1 个)
Daniel Shub
2011-10-18
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.
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!