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.

  1. clc; %for clear screen
  2. close all; %for closing all windows
  3. clear all; %for clearing workspace
  4. disp=input('Hello world');

Program 2

WAP to show the basic arithmetic operations.

  1. clc; %for clear screen
  2. close all; %for closing all winndows
  3. clear all; %for clearing workspace
  4. a=input('enter a number');
  5. fprintf('a=%f\n',a);
  6. b=input('enter another number');
  7. fprintf('b=%f\n',b);
  8. c=a+b;
  9. d=a-b;
  10. e=a*b;
  11. f=a/b;
  12. fprintf('sum of a and b = ');
  13. fprintf('%f\n',c);
  14. fprintf('difference of a and b = ');
  15. fprintf('%f\n',d);
  16. fprintf('multiplication of a and b = ');
  17. fprintf('%f\n',e);
  18. fprintf('division of a and b = ');
  19. 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.

  1. clc;
  2. close all;
  3. clear all;
  4. dist=input('the distance between two cities in kms');
  5. mtr= dist*1000;
  6. fprintf('distance in meters=%d\n',mtr);
  7. fet= dist*3280.83;
  8. fprintf('distance in feet=%d\n',fet);
  9. inch=dist*39370.07;
  10. fprintf('distance in inch=%d\n',inch);
  11. cms=dist*100000;
  12. fprintf('distance in cms=%d\n',cms);

Program 4

WAP to find the simple interest of a principal amount given through keyboard.

  1. clc;
  2. close all;
  3. clear all;
  4. p=input('the principal amount is =');
  5. fprintf('p=%f\n',p);
  6. t=input('the time period is =');
  7. fprintf('t=%f\n',t);
  8. r=input('the rate of intrest is =');
  9. fprintf('r=%f\n',r);
  10. si= (p*t*r)/100;
  11. fprintf('the simple intest is = %f',si);

Program 5

WAP to convert the temperature from Centigrade to Fahrenheit vice versa

  1. clc;
  2. close all;
  3. clear all;
  4. C1= input('the temp in Centigade = ');
  5. F1= (C1*9/5)+32;
  6. fprintf('the temp in Fahrenheit = %f',F1);
  7. F2= input('\nthe temp in Fahrenheit = ');
  8. C2 = (F2-32)*5/9;
  9. fprintf('the temp in Centigrade = %f',C2);

Program 6

WAP to find the parimeter and area of  a rectangle through keybord input.

  1. clc;
  2. close all;
  3. clear all;
  4. l=input('the length of the rectangle = ');
  5. b=input('\nthe breadth of the rectangle = ');
  6. P=2*(l+b);
  7. fprintf('\nthe perimeter of the rectangle  = %f',P);
  8. A=(l*b);
  9. fprintf('\nthe area of the rectangle  = %f',A);

Program 7

WAP to find the parimeter and area of  a circle through keybord input.

  1. clc;
  2. close all;
  3. clear all;
  4. r=input('the length of the radius of the circle = ');
  5. P=2*pi*r;
  6. fprintf('\nthe perimeter of the circle = %f',P);
  7. A=pi*r^2;
  8. 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.
contact-form

Post a Comment

If you have any doubts regarding this topic...
feel free to ask...

Previous Post Next Post