MATLAB QUESTION Note: Present results using fprintf commands and comment your co
ID: 3887738 • Letter: M
Question
MATLAB QUESTION
Note: Present results using fprintf commands and comment your code throughout. 1. You are implementing a new screen for your process that has some constraints. The diagonal size of the screen cannot be bigger than 40 inches (Hint: The screens are rectangles). Create a code that will verify the diagonal size using the height and width of proposed screen sizes and determine if it fits or not. Using fprintf your code should tell the user "Fits!" or "ERROR, does not fit" for the each case. Use the following dimensions: a. Height: 10, Width: 30 b. Height: 20, Width: 30 c. Height: 10, Width: 40 2. write a code that determines the real roots of a quadratic equation ax2 + bx + c 0, when the code runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation, the program calculates the discriminant D, given by D=b2-4ac If D >0, the code should display "The equation has two roots" and display the values on a new line. If D = 0, the code should display "The equation has one root.", and display the values on a new line. If D 0, the code should display “The equation has no real roots." Run the script with the following equations: a. 2x2 + 8x +8=0 b. -5x2 + 3x-4=0 c, -2x2 + 7x + 4-0 3. Create a code that converts one unit of energy into another. The code will convert Joules into: calorie, british termal unit (BTU), and Kilowatt-hour (kWh). The code should be able to convert these units back to Joules. Ask the user for what unit conversion he desires (in the form of a string - ex. JtoC for joules to calorie). Then, use a switch statement to determine which unit conversion will be performed and perform the calculation. Use the following unit conversions and values for your problem: a. 1540 Joules ? BTU b. 100,000 Joules ? Calories c. 580 Joules ? kWh d. 5291 kWh ? Joules e. 1684 Calories ? Joules f. 852,000 BTU ? JoulesExplanation / Answer
Question 1 Matlab code:
height = input('Enter the height of screen in inches'); %input height
width = input('Enter the width of screen in inches'); %input width
diagonal = sqrt( height^2 + width^2); %calculate diaonal
if(diagonal > 40) % check if diagonal > 40
fprintf('Error,does not fit');
else
fprintf('Fits!');
end
Sample Output:
Question 2:
clc;
a = input('Enter the value of a'); %input value of a
b = input('Enter the value of b'); %input value of b
c = input('Enter the value of c'); %input value of c
D = b^2 - 4*a*c; %calculate D
if(D > 0)
fprintf('The equation has two real roots!');
elseif(D == 0)
fprintf('The equation has 1 real root!');
else
fprintf('The equation has no real root!');
end
Sample Output:
Question 3:
Matlab code:
clc;
fprintf('Enter 1 to convert joule to BTU ');
fprintf('Enter 2 to convert joule to Calorie ');
fprintf('Enter 3 to convert joule to kW-h ');
fprintf('Enter 4 to convert BTU to joule ');
fprintf('Enter 5 to convert Calorie to joule ');
fprintf('Enter 6 to convert Kw-h to joule ');
choice = input('');
if(choice == 1)
joule = input('Enter energy in joule!')
BTU = joule*0.000947817;
fprintf('%d joule = %d BTU', joule, BTU);
elseif(choice == 2)
joule = input('Enter energy in joule!')
calories = joule*0.000239006;
fprintf('%d joule = %d calories', joule, colories);
elseif(choice == 3)
joule = input('Enter energy in joule!')
kwh = joule*2.77778*(10^-7);
fprintf('%d joule = %d KW-h', joule, kwh);
elseif(choice == 4)
BTU = input('Enter energy in BTU!')
joule = BTU*1055.06;
fprintf('%d BTU = %d joule', BTU, joule);
elseif(choice == 5)
colories = input('Enter energy in colories!');
joule = colories*4184;
fprintf('%d colories = %d joule', colories, joule);
elseif(choice == 6)
kwh = input('Enter energy in kwh!');
joule = kwh*3.6*10^6;
fprintf('%d KW-h = %d joule', kwh, joule);
else
fprintf('Invalid input please enter a option from 1 to 6!')
end
Sample Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.