Skip to main content

Weight converter Kilograms to Pounds: Matlab

Problem

Create a variable kilos to store the weight in kilograms and convert it into pounds using Matlab. Show the result in a neat text fashion. The conversion factor is 1 Pound = 0.453592 Kilograms.

Solution

This problem has been a sequel of the recent post on radiusofcircle.blogspot.com and can be found here: Weight to convert Pounds to Kilograms. This post is similar to that and if you have solved the prequel post then I suggest you to solve this problem by your own and verify the solution with the one posted here. In this problem we will request the user to input the value of the weight in kilograms and store it in a variable. Now we will use the conversion factor and store the value of the result in another variable. We will finally display the value to the user.Some of the key concepts in that you need to know in Matlab to solve this problem are as follows:
I suggest you to know about both fprintf and disp functions, but for now if you know any one of them you can manage to solve this problem. Checkout the explanation of the program below the program section if you didn't understand the program.

Program


%Ask the user to input the weight in Kilograms
kilos = input('Enter the weight in Kilograms: ');
%convert kilos to pounds using conversion factor
pounds = 0.453592*kilos;
fprintf('Weight of %f kilos is %f pounds\n',kilos,pounds)
I have named this file as kilos_to_pounds.m for using this is Matlab command line interface.

Explanation

The above code is simple if you know the basics of Matlab. In the above code we are taking the input of the user asking to Enter the weight in kilograms. Then we convert the kilos to pounds using the conversion factor 1 pound = 0.453592 kilos. Finally we print the output in a very user friendly way so that the user will understand it easily.

Input/Output

Kilos_to_pounds trial run - Matlab Interface
Trial run for kilos_to_pounds.m file
I have tried to explain the code so that it will be easy even for the beginners to understand. If you have any doubt or didn't understand any part of the program then please do contact me from here: contact me, or comment below. This will not only help you but also help others.

Comment you trial run of kilos_to_pounds in the comment below.

Keywords: matlab, pounds, kilos, weight, conversion

Popular posts from this blog

Project Euler Problem 67 Solution with Python

Maximum path sum II By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 3 7 4 2 4 6 8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file containing a triangle with one-hundred rows.

Making a quiz web app with python and flask

Edit : When you are creating a web app with h tml templates, then y ou will have to sa ve the html file in templates folder in the Current Wor ki ng Directory( CWD). If you save the file in the C W D directl y you will get a TemplateNotFound error. Thank you Udhay for pointing it out.   In this post we will create a quiz website using python . I will be using the flask framework . After reading this tutorial you will learn form submission , flask templates , python code in flask templates , shuffling the questions and options with the random module and few others.  Please note that this tutorial is not big as it seems to be. Some of the code has been rewritten to maintain consistency and also font size is somewhat big so that your eyes won't get stressed reading this tutorial. Also the content has not occupied the full width of the page. In this tutorial I am assuming that you are having a very basic understanding of the flask framework . Please refer the documenta...

Project Euler Problem 66 Solution with python

Diophantine equation ¶ Consider quadratic Diophantine equations of the form: $$ x^{2} – Dy^{2} = 1 $$ For example, when $D = 13$, the minimal solution in $ x $ is $ 649^{2} – 13 \times 180^{2} = 1 $ It can be assumed that there are no solutions in positive integers when $ D $ is square. By finding minimal solutions in $ x $ for $ D = {2, 3, 5, 6, 7} $, we obtain the following: $$ 3^{2} – 2×2^{2} = 1 $$ $$ 2^{2} – 3×1^{2} = 1 $$ $$ 9^{2} – 5×4^{2} = 1 $$ $$ 5^{2} – 6×2^{2} = 1 $$ $$ 8^{2} – 7×3^{2} = 1 $$ Hence, by considering minimal solutions in $ x $ for $ D ≤ 7 $, the largest $ x $ is obtained when $ D = 5 $. Find the value of $ D ≤ 1000 $ in minimal solutions of $ x $ for which the largest value of $ x $ is obtained.