Like C language you can write some basic programs using MATLAB which is as simple as writing programs in C.
Here I discuss some basic programs to create an idea, how we are going to write a program in MATLAB incoming future.
Program 1
WAP to print Hello World.
- clc; %for clear screen
- close all; %for closing all windows
- clear all; %for clearing workspace
- disp=input('Hello world');
Program 2
WAP to show the basic arithmetic operations.
- clc; %for clear screen
- close all; %for closing all winndows
- clear all; %for clearing workspace
- a=input('enter a number');
- fprintf('a=%f\n',a);
- b=input('enter another number');
- fprintf('b=%f\n',b);
- c=a+b;
- d=a-b;
- e=a*b;
- f=a/b;
- fprintf('sum of a and b = ');
- fprintf('%f\n',c);
- fprintf('difference of a and b = ');
- fprintf('%f\n',d);
- fprintf('multiplication of a and b = ');
- fprintf('%f\n',e);
- fprintf('division of a and b = ');
- fprintf('%f\n',f);
Program 3
The distance of between two cities (in km) is input through the keyboard. WAP to convert the distance of the city in meters, feet, inches, cm.
- clc;
- close all;
- clear all;
- dist=input('the distance between two cities in kms');
- mtr= dist*1000;
- fprintf('distance in meters=%d\n',mtr);
- fet= dist*3280.83;
- fprintf('distance in feet=%d\n',fet);
- inch=dist*39370.07;
- fprintf('distance in inch=%d\n',inch);
- cms=dist*100000;
- fprintf('distance in cms=%d\n',cms);
Program 4
WAP to find the simple interest of a principal amount given through keyboard.
- clc;
- close all;
- clear all;
- p=input('the principal amount is =');
- fprintf('p=%f\n',p);
- t=input('the time period is =');
- fprintf('t=%f\n',t);
- r=input('the rate of intrest is =');
- fprintf('r=%f\n',r);
- si= (p*t*r)/100;
- fprintf('the simple intest is = %f',si);
Program 5
WAP to convert the temperature from Centigrade to Fahrenheit
vice versa
- clc;
- close all;
- clear all;
- C1= input('the temp in Centigade = ');
- F1= (C1*9/5)+32;
- fprintf('the temp in Fahrenheit = %f',F1);
- F2= input('\nthe temp in Fahrenheit = ');
- C2 = (F2-32)*5/9;
- fprintf('the temp in Centigrade = %f',C2);
Program 6
WAP to find the parimeter and area of a rectangle through keybord input.
- clc;
- close all;
- clear all;
- l=input('the length of the rectangle = ');
- b=input('\nthe breadth of the rectangle = ');
- P=2*(l+b);
- fprintf('\nthe perimeter of the rectangle = %f',P);
- A=(l*b);
- fprintf('\nthe area of the rectangle = %f',A);
Program 7
WAP to find the parimeter and area of a circle through keybord input.
- clc;
- close all;
- clear all;
- r=input('the length of the radius of the circle = ');
- P=2*pi*r;
- fprintf('\nthe perimeter of the circle = %f',P);
- A=pi*r^2;
- fprintf('\nthe area of the circle = %f',A);
IF YOU HAVING ANY DOUBTS REGARDING THESE PROGRAMS, JUST LET ME KNOW BY YOUR COMMENTS OR YOU CAN ALSO ASK ME IN THE COMMENT BOX OR THROUGH EMAIL.
I WILL TRY TO SOLVE YOUR PROBLEMS AS SOON AS POSSIBLE.
Post a Comment
If you have any doubts regarding this topic...
feel free to ask...