answer each question with the code (1 point write the number 0.0035 using expone
ID: 3846376 • Letter: A
Question
answer each question with the code
Explanation / Answer
Here is the matlab code for the question. Please don't forget to rate the answer if it helped. Thank you very much.
%question 1, prints 0.0035 in exponential format i.e 3.5000E-03
format shortE
x = 0.0035
%question 2, ask user for input name
name1 = input('Enter your name:', 's');
%question 3, compare user input with string Davison
name2 = 'Davison';
if (strcmp(name1 , name2))
fprintf("Welcome professor %s ", name1);
else
if(name1(1) == 'D') %get the 1st character in the name and compare with 'D'
fprintf("Your name starts with D ");
else
fprintf("Your name does not start with D ");
end
end
% question 4, summing matrix elements
format short
m = [1 2; 3 4]
%sum returns a row matrix by summing the columns in a matrix
total = sum(m);
%keep calling sum, till we end up with a single element in the total
%store the result back into total
while(numel(total) != 1)
total = sum(total) ;
end
total
%question 5, generat random number in a range
%define the lower and higher end of range and then generate random number
%using rand() function
lo = -5;
hi = 5;
r = lo + (hi - lo) * rand()
output
x = 3.5000E-03
Enter your name:Davison
Welcome professor Davison
m =
1 2
3 4
total = 10
r = -4.7515
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.