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

Function M-file a. Create a function M-file that will evaluate the following fun

ID: 3111977 • Letter: F

Question

Function M-file a. Create a function M-file that will evaluate the following function below: f(x, y) = x ln(y) Test the function in a separate script m-file or command window with the following: y = natlog (1, 2) b. Define a function m-file that will calculate f(x, y, z) = xy^2 z^0.5 that is able to handle vectors for inputs of x, y, z. Test the functions with appropriate input of your choice. c. Create a function M-file to calculate the norm, magnitude, of a random set of vectors. Test the function.

Explanation / Answer

a) %%% Function

function f = natlog ( x,y)
f=x*log(y);

%%Test Code

clc;

clear all ;

close all;

f=natlog(1,2)

OUTPUT:

f=0.6931

b)

%% Function

function f = prod_xyz (x,y,z);
for n= 1:length(x)
    f(n)=x(n)*y(n)^2*z(n)^0.5;
end

%%% Test code

f=prod_xyz(1,2,3)
x=[1,2,3];
y=[4,3,2];
z=[4,1,7];
f1=prod_xyz(x,y,z)

OUTPUT:

f =

    6.9282


f1 =

   32.0000   18.0000   31.7490

c)

%% function code

function [n,m] = vect_s (a);
n=max(abs(a));
m=sqrt(sum(a.^2));

%% Test code

y=[4,3,2];
[n,m]=vect_s(y)

OUTPUT:

n =

     4


m =

    5.3852