Q:

Write a function eqfn that will calculate f(x) = x 2  1 x for all elements of x. Since division by 0 is not possible, if any element in x is zero, the function will instead return a flag of -99. Here are examples of using this function:

0

 Write a function eqfn that will calculate f(x) = x 2 + 1 /x for all elements of x. Since division by 0 is not possible, if any element in x is zero, the function will instead return a flag of -99. Here are examples of using this function: 

>> vec = [5 0 11 2];

>> eqfn(vec)

ans =

 -99

>> result = eqfn(4)

result =

 16.2500

>> eqfn(2:5)

ans =

 4.5000 9.3333 16.2500 25.2000

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function fofx = eqfn(x)

if any(any(x==0))

 fofx = -99;

else 

 fofx = x.^2 + 1./x;

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now