Built-in function
Log();
Sqrt();
Area=pi*r^2
Circumference=2pi*r
Loops
1)FOR loop
syntax
for i=initial value:increment:termination point
statement
like As
for i=0:1:10
statement
e.g.
sum=0;
for x=1:1:10
sum=sum+x;
fprintf(‘Sum=’,sum);
end
program
1)sum of all the even # from 0 to 20
While loop
Syntax
While i<10
Statement
i=i+1;
Conditional statement
1)If
Syntax
If(x<10)
Statement
2)
if else
if(x<10)
statement
else
statement
end
end
plot(x,y)
x=0:10:1000;
y=x.^2;
y=x.^3
x label(‘x-axis’);
y label(‘y-axis’);
title(‘Hello word’);
Grid on; /*command for graphs*/
Hold on;/*command for Graph*/
Z=x^.3
Plot(x,z);
Hold off;
Write a program which input one number if number is even then your program display table of that number but range of table must be o to 15 but if the input number is
And odd number then your program show table of that number which range is o to 10.
Best of luck
n =input(‘Enter a number \n’);
if(mod(n,2)= =0)
for x=0:1:15
fprintf(‘%d*%d=%d\n’,n,x,n*x);
else
for x:0:1:10
fprintf(‘%d*%d=%d\n’,n,x,n*x);
end
Plot a Graph for specific Range
Plot(x,a)
Y=[-100:20:100]
Plot(y)
Length(y)
Subplot(2,2,1)
Plot(z)
Subplot(2,2,2)
Plot(y)
Subplot(2,2,3)
Roots
Y=[1 0 4 2 0 9 ]
root(y)
0 comments:
Post a Comment