Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using matlab... Using function, if/if-else statment, any/all/ Write a function n

ID: 2079971 • Letter: U

Question

Using matlab...

Using function, if/if-else statment, any/all/ Write a function named calc_f that will calculate and reture f(x)=(1/x+1)+(1/x-2) for all elements of the input vector. However, division by zero has no meaning in arithmetic, which will happen when x is -1 or +2. Thus, by some design choices, the function is chosen to return an empty matrix if any element in the input vector x causes divison by zero. You may assume that the input vector will not be empty. Note: division by zero in MATLAB will generate inf. for example, try 1/0.

Explanation / Answer

main:

function matrix =clc_f(x)
  
matrix = [];
  
for i=1:length(x)
if (x(i)==-1 || x(i)==2)
return
end
end

matrix = ((1./(x+1)) + (1./(x-2)));
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote