How would you write piecewise functions in matlab that can take vector inputs?(adsbygoogle = window.adsbygoogle || []).push({});

Here's a function that I'm trying to write.

If I call g([0,pi/2]), I want it to return [0,2/pi], but what I get instead is [NaN,2/pi]. I'm guessing when I write x==0, matlab is comparing the entire input to 0.Code (Text):

function y=g(x)

if x==0

y=1;

else

y=sin(x)./x;

end

**Physics Forums - The Fusion of Science and Community**

# Defining piecewise function in matlab

Know someone interested in this topic? Share a link to this question via email,
Google+,
Twitter, or
Facebook

- Similar discussions for: Defining piecewise function in matlab

Loading...

**Physics Forums - The Fusion of Science and Community**