Complete Problem 1 and Problem 3 in MATLAB Create a single script (.m file) to c
ID: 3849939 • Letter: C
Question
Complete Problem 1 and Problem 3 in MATLAB
Create a single script (.m file) to complete this assignment. Unless directed otherwise, use meaningful variable names for each variable; do not use the default variable ans to store your results. For this assignment suppress your output with semi-colons (;). Each problem (i.e. Problem 1 and Problem 3) should be in a separate cell, using the cell mode feature of MATLAB; the subparts should all be contained in the same cell as the parent problem.
T 1 4 7 1. Consider the matrix A 9 3 4 Request the matrix from the user with the input command. With the find 6 8 2 command, use a print command to print these results to the Command Window: a) Programmatically count how many elements of the matrix A are equal to 4. b) Programmatically count how many elements of the matrix A are less than 5 or greater than 7.Explanation / Answer
Question 1:
Matlab code:
clear all;
fprintf('Please Enter the input matrix ');
matrix = input('');
%part a
count_fours = sum(sum(matrix == 4))
%part b
count_less_than_5_or_more_than_7 = sum(sum(matrix < 5 | matrix > 7))
Sample Output:
Question 3
clear all;
fprintf('Please Enter the input value ');
x = input('');
if(x <= 0)
fprintf('Error, input value is not in domain of ln(x) ');
elseif(0 < x && x < 1)
fprintf('Warning, ln(x) will be less than 0 for x = %d ', x);
else
tmp = log(x);
fprintf('ln(x) = %d ',tmp);
end
Sample Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.