Question

Please show in MATLAB code using if and else statements if necessary Write a program in a script ...

Please show in MATLAB code using if and else statements if necessary

Write a program in a script file that converts a quantity of energy given in units of either J (Joules), Btu, or (ft-lb) to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of power in the new units using the fprintf command.
Conversion factors are: 1

0 0
Answer #1

Matlab code

============================================================================================

energy=input('enter the quantity of energy: ');

u1=input('enter current unit of enenry (Joules), (Btu), or (ft-lb) ','s');

u2=input('enter new desired units(Joules), (Btu), or (ft-lb) ','s');

%input unit is Joules
if(strcmpi(u1,'Joules'))
if(strcmpi(u2,'Btu'))
output=energy*9.478*10^-4;
elseif(strcmpi(u2,'ft-lb'))
output=energy*0.7376;
end
elseif(strcmpi(u1,'Btu')) %input unit is Btu
if(strcmpi(u2,'Joules'))
output=energy* 1055.05585262;
elseif(strcmpi(u2,'ft-lb'))
joules=energy* 1055.05585262;
output=joules*0.7376;
end
elseif(strcmpi(u1,'ft-lb')) %input unit is ft-lb
if(strcmpi(u2,'Joules'))
output=energy*1.35582;
elseif(strcmpi(u2,'Btu'))
joules=energy*1.35582;
output=joules*9.478*10^-4;
end
end

fprintf('energy in %s is %f\n',u2,output);

============================================================================================

Output

MAILAB R2018a PUE ISH Lng h Find Files Compare ▼ Print Run Sect on Go To, Comment % SFnd▼ Naw Cpen Save Breakpoints Run Run a

Know the answer?
Add Answer to:
Please show in MATLAB code using if and else statements if necessary Write a program in a script ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use Matlab to solve and show your full codes Write a script file Ask the...

    Please use Matlab to solve and show your full codes Write a script file Ask the user to enter sides of a triangle: a, b, c Check to see if the sides are all greater than 0 If they are: Use the function (triangle) that you created in your last homework problem (HW#5 problemttF) to calculate the area. command Display the results on the screen using fprintf write the results to disk using the fprintf command. If any of the...

  • This question is for MATLAB. Write a script that continuously asks the user for a new...

    This question is for MATLAB. Write a script that continuously asks the user for a new sentence, until the user types the word "STOP". The program records all of the sentences the user wrote (not including "STOP") in a matrix with as many rows as needed but with an N number of columns. The user is prompted to provide N before typing in the first sentence. The output of the program is the array with the sentences in it, in...

  • Please write the script for following problem in MATLAB. Write a script with a file name...

    Please write the script for following problem in MATLAB. Write a script with a file name Problem3.m that, when executed, prints 1.99 dollars per unit. How many units will you purchase? [new line] Then control is given back to the user to input a scalar integer quantity. The script then prints out __ units at 1.99 dollars per unit is a total of ___ dollars. [new line] where the first blank is filled with whatever number was inputted by the...

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • Please help with this code For the following problem write a Matlab® script file with clear...

    Please help with this code For the following problem write a Matlab® script file with clear commentary for each line of code. Your script should: Load the data in the problem as a text file. Calculate the statistics using Matlab  functions. Solicit input from the user of the reading (for example, 137 degrees as stated in the problem). In another word, the reading should not be fixed in the script and has to be entered and saved from the command window...

  • Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y =...

    Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y = sin(x) from x = 0 to 21. 12) Plot the functions y = x2 z = x2 + 2x + 1 from x = 0 to 2 on the same graph. Scripts: Input and Output 13) Write a script (M-file) to read in a message at the command line using the MATLAB input function and then display the message to the Command Window using...

  • USING MATLAB Write a script that asks the user to input a sentence. It then replaces...

    USING MATLAB Write a script that asks the user to input a sentence. It then replaces all instance of 'he', 'she', 'He', or 'She' with 'Mr. Meseeks' and prints out the new sentence. . HINT: Use 'strrep' and 'lower' function.

  • Using MATLAB program to solve the following question please: Write a script called echostring that will...

    Using MATLAB program to solve the following question please: Write a script called echostring that will prompt the user for a string, and will echo print the string in quotes (with an extra little surprise at the end): >> echostring Enter your string: I like nap Your string was: ‘I like nap – in MATLAB class’

  • Write a script using the bash shell to add new users to the system. The script...

    Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma). The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause. The input file should contain the user information with one user per line. As the system administrator, you should determine the information necessary for each user to properly...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT