Question: Question 1 . Use MATLAB built - in functions to calculate sum, average, maximum, and minimum, all in one function, for an array of numbers.
Question Use MATLAB builtin functions to calculate sum, average, maximum, and minimum, all in one
function, for an array of numbers. The array of numbers should be input by user:
Instructions:
Create a function named calculateStats that takes a vector as input and returns the sum, average,
maximum, and minimum.
Write a script that prompts the user to input a list of numbers, stores the numbers in a vector, and
then passes the vector to the calculateStat function to display the results.
The script should handle errors for invalid inputs eg nonnumeric entries
Guidelines for Report: Explain the purpose of each function, provide a flowchart of the algorithm, and
discuss any issues encountered.
Question Create a MATLAB Script for Plotting Functions using fplot ask the user to enter a function eg
sinx and x Specify the range for input x put title, and label x and y axes; finally, for better
illustration the plot should be in grid form.
Steps:
Prompt the user to input a function in the form of a MATLAB expression egsinxexpx
etc.
Ask the user to specify the range of x values.
Plot the function over the specified range using the fplot function.
Guidelines for Report: Describe how to input functions in MATLAB, discuss limitations eg
unsupported functions and include plots for multiple examples.
Question Implement Fibonacci Sequence once with for loop and once with while loop first ask the user to
enter the number of Fibonacci numbers and display the result.
Instructions:
Write a script that generates the first n Fibonacci numbers, where n is specified by the user.
Include options for using a for loop and a while loop. Compare the implementations.
Guidelines for Report: Explain how different loop structures work, include the scripts for both
approaches, and discuss the differences in performance or readability.
Question Use a for loop and conditional statement if to create a script to find numbers divisible by both
and in a given range eg: to ; display the result using dispNumbers divisible by both and
are:;
Instructions:
Prompt the user to specify a range eg from a to b
Find and display all numbers within this range that meet the divisibility criteria.
Guidelines for Report: Describe the use of conditional statements for divisibility checks, include
results for various ranges, and discuss how different ranges affect the performance.
Question a Write the scripts for the Bisection, NewtonRaphson and Secant Methods; start with the following
functions
bisectionRoot bisectionMethodfe;
newtonRoot newtonRaphsonf dfe;
secantroot
for example f can be the following function
f @x xx ;
df @xx;
Instructions: Write a function for the Bisection method that accepts an initial interval, tolerance, and maximum
iterations.
Implement a function for the NewtonRaphson method, requiring an initial guess and the derivative
of the function.
Test these functions with the equation fx xx
Guidelines for Report: Provide the theoretical background of each method, include the MATLAB
code, and discuss the convergence behavior of these methods.
b For performance comparison, create a script that compares the results of these methods for different
functions.
Instructions:
Create a script that calls these functions for various test cases, including functions with different
characteristics eg multiple roots, steep gradients
Measure the number of iterations and computational time.
Guidelines for Report: Present the results in tables and plots, explain why one method may outperform
the other for certain functions, and discuss the limitations
Question Develop an Mfile function based on Gauss elimination with partial pivoting to implement Gauss
elimination with partial pivoting. Modify the function so that it computes and returns the determinant
with the correct sign and detects whether the system is singular based on a nearzero determinant. For
the latter, define nearzero as being when the absolute value of the determinant is below a tolerance
eg: When this occurs, design the function so that an error message is displayed, and the
function terminates.
Here is the functions first line:
functionxDGaussPivotNewAbtol
where Dthe determinant and tolthe tolerance, tol
Guidelines for Report: Explain the purpose of partial pivoting method, and discuss any issues
encountered.
Conclusion
For each of the problems, write short conclusion.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
