0% found this document useful (0 votes)
6 views

MATLAB_Function_Report_Expanded

The document provides a report on three MATLAB functions: `addTwoNumbers`, which sums two numbers; `squareNumber`, which calculates the square of a number; and `checkSign`, which determines if a number is positive, negative, or zero. Each function is explained with sample inputs and expected outputs, demonstrating basic arithmetic, mathematical operations, and conditional structures in MATLAB. The report serves as a practical guide for writing and understanding functions in MATLAB programming.

Uploaded by

envermuh455
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MATLAB_Function_Report_Expanded

The document provides a report on three MATLAB functions: `addTwoNumbers`, which sums two numbers; `squareNumber`, which calculates the square of a number; and `checkSign`, which determines if a number is positive, negative, or zero. Each function is explained with sample inputs and expected outputs, demonstrating basic arithmetic, mathematical operations, and conditional structures in MATLAB. The report serves as a practical guide for writing and understanding functions in MATLAB programming.

Uploaded by

envermuh455
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MATLAB Function Report

Name: [Your Name]

Date: [Insert Date]

Function 1: Sum of Two Numbers


function result = addTwoNumbers(a, b)
result = a + b;
end

Question 1:

What does the `addTwoNumbers` function do, and what will it return if we input the numbers 3 and 5
into it?

Answer:

This function simply takes two input numbers, adds them together, and returns the result. If we call
`addTwoNumbers(3, 5)`, the function adds 3 and 5 to give 8 as the output. It demonstrates basic
arithmetic in MATLAB and helps in practicing how to write and use functions with input and output
parameters.

Function 2: Square of a Number


function result = squareNumber(x)
result = x^2;
end

Question 2:

What is the output of calling the `squareNumber` function with the input value 4?

Answer:

This function calculates the square of the given input number. When we call `squareNumber(4)`, the
function computes 4 raised to the power of 2, which is 16. It is useful in many mathematical
applications and is a good example of using mathematical operators inside MATLAB functions.

Function 3: Check Positive or Negative


function checkSign(n)
if n > 0
disp('Positive number')
elseif n < 0
disp('Negative number')
else
disp('Zero')
end
end

Question 3:

What will happen when the `checkSign` function is executed with an input of -10?

Answer:

The function checks whether a number is positive, negative, or zero. It uses an if-elseif-else
conditional structure. When we call `checkSign(-10)`, the number -10 is less than 0, so the function
will display the message: 'Negative number'. This function is helpful to understand conditionals and
decision-making in MATLAB programming.

You might also like