MATLAB
- create MATLAB functions to convert kilometers to miles and vice versa according to the following conditions. (a) The functions created will have input of miles or kilometers and the output with converted kilometers or miles. (b) The output of the function should be a conversion table. No input for the function is needed. (1 mile = 1 609.344 meter)
- function with the following: (1) output a third-order polynomial function with the coefficients as the input variables; (2) Convert this function to function handle.
(a) MATLAB CODE:
function Conversion(Xmile,Xkm)
mile = 1.609344; % 1 mile = 1.609344 Km
km = 1/mile; % Kilometer to miles
Ykm = Xmile*mile; % Converting miles to Kilometers
fprintf('%d mile = %d Km\n',Xmile,Ykm)
Ymile = Xkm*km; % Converting Kilometers to miles;
fprintf('%d Km = %d mile\n',Xkm,Ymile)
end
OUTPUT:
(b) MATLAB CODE:
function Conversion
Xmile = 1:10;
Xkm = 1:10;
mile = 1.609344; % 1 mile = 1.609344 Km
km = 1/mile; % Kilometer to miles
Ykm = Xmile*mile; % Converting miles to Kilometers
Ymile = Xkm*km; % Converting Kilometers to miles;
Kilometers = transpose(Xkm);
Kilometers_to_Miles = transpose(Ymile);
Miles = transpose(Xmile);
Miles_to_Kilometers = transpose(Ykm);
T =
table(Kilometers,Kilometers_to_Miles,Miles,Miles_to_Kilometers);
fprintf('Conversion Table:\n')
disp(T)
end
OUTPUT:
3rd Order Polynomial:
MATLAB CODE:
function Order3(a,b,c,d)
syms x % using x as a variable
p(x) = a*x^3+b*x^2+c*x+d ; % Third order polynomial
fprintf('Third order polynomial with %d,%d,%d,%d as
coefficients:\n',a,b,c,d)
disp(p(x))
end
OUTPUT:
MATLAB - create MATLAB functions to convert kilometers to miles and vice versa according to the...
Write a program that will convert miles to kilometers and kilometers to miles. The user will indicate both a number (representing a distance) and a choice of whether that number is in miles to be converted to kilometers or kilometers to be converted to miles Each conversion is done with a value returning function You may use the following conversions. 1 kilometer = .621 miles 1 mile = 1.61 kilometers Sample Run: Please input Convert miles to kilometers Convert kilometers...
part 1: Create Useful Functions. Create the following functions in MATLAB and use the function names provided below! kmout = MilesToKm(miles) % converts a value in miles to kilometers kJoulesOut = CalTokJoules(DietaryCalories) % converts dietary calories (big calories) to kiloJoules (10^3 Joules = 1 kJ) kWhrOut = KJoulesToKWHr(Kjoules) % converts kJoules to kilowatt hours kmout = FeetTokm(feet) % converts feet to kilometers secondsout = HoursToSeconds(hours) % converts hours to seconds Each of the functions includ appropriate help comments that will...
Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...
Assignment: Do this assignment after reading zyBooks Chapter 3. Create the following functions in MATLAB and save them to your directory. You must use the function names provided below! Use the attached test script TestConversions.m to test your functions. kmout = MilesToKm(miles) % converts a value in miles to kilometers JoulesOut = CalToJoules(DietaryCalories) % converts dietary calories (big calories) to Joules kWhrOut = JoulesToKWHr(joules) % converts Joules to kilowatt hours metersout = FeetToMeters(feet) % converts feet to meters secondsout =...
1
Write a program to convert the time from 24-hour notation to
12-hour notation and vice versa. Your program must be menu driven,
giving the user the choice of converting the time between the two
notations. Furthermore, your program must contain at least the
following functions:
a function to convert the time from 24-hour notation
to 12-hour notation,
a function to convert the time from 12-hour notation
to 24-hour notation,
a function to display the choices, function(s) to get
the...
FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...
MATLAB Homework 3- Due:5/20/2018 1. Create a function that receives the following input data, and prints the output as the summation of the diagonal elements (The elements which are located at the intersection of similarly numbered rows and columns) Input (Matrix A) Output (Scalar B) Example 2 -1 4 3 -45 ? B = A( 1,1) + A(2,2) = 2-4 =-2 A4 5 ?41 ? B = A(1,1) + A(2,2)--1-4-5 -3 1 1.5 -4 3.2 -1 06 1.78 2.22 -4.56...
MATLAB HELP : Create a MATLAB function starting as follows:- Function [root1,root1] = quadraticroots (a,b,c) to find the roots of a quadratic function. To test your function find the roots of the following equation:- X^2+5x+6=0 Submit the complete listing and results of a run with the variable a=1,b=5 and c=6. Your file should contain at least the following:- Purpose of the function, Description of the input and output variables, Call statement(s), PLEASE SHOW FULL SCRIPT OF THE MATLAB with results...
Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...
DO THIS IN MATLAB PLEASE
DO THIS IN MATLAB
Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...