Should I handle unexpected arguments of a function?

How should I approach writing a MATLAB function evaluating a conditional logarithmic function with a variable number of arguments?

  • Write a Matlab function call_functions to evaluate the function      f(x,y)=ln(1/1-x)*ln(1/1-y).       Note that call_function will have two input arguments x and y and this function will call f_x [which equals ln(1/1-x)] function twice to evaluate f(x,y).   From the command window test your program for x=0.5, y=0.5 and x=1, y=0.5. For #3 use the script for number 2.   function if [f_xy]=-999999; else [f_xy]=log((1-x)^(-1))*log((1-y)^(-1)); end         If anyone could help understand how to approach this it would really help!   Thanks.   And would I am vague on commands such as feval, eval, and nargin. And vague on applying subfunctions and nested functions.   Any approach would help. Please explain in laymens terms.

  • Answer:

    First, learn to use .* ./ .^ There is nothing telling you that your input will be scalars and not vectors or matrices. This  assignment calls for using subfunctions. At the end of your function you should add function f=f_x(z) f=log(1./(1-z)); end Then you should call it in your formula like this: f_xy=f_x(x).*f_x(y); ...

Achilleas Vortselas at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.