You are on page 1of 8

>> 1+2*3

ans =
7

>> x = 1+2*3
x=
7

>> 4*x
ans =
28.0000

>> t = 5;
>> t = t+1
t=
6

>> (1+2)*3
ans =
9

>> a=7; b=cos(a), c=cosh(a)


b=
0.6570
c=
548.3170

>> a = 5; x = 2; y = 8;
>> y = exp(-a)*sin(x)+10*sqrt(y)
y=
28.2904

>> exp(10)
ans =
2.2026e+004
>> w = [1;4;7;10;13]
w=
1
4
7
10
13

>> v = [1 4 7 10 13]
v=
1 4 7 10 13
>> w = v’
w=
1
4
7
10
13

>> v(1:3)
ans =
147

>> v(3,end)
ans =
7 10 13

>> eye(3)
ans =
100
010
001

>> c=zeros(2,3)
c=
000

>>linspace(0,10,5)
ans =

Columns 1 through 3

0 2.5000 5.0000
Columns 4 through 5

7.5000 10.0000

>>a = input('Enter coefficient a: ');


b = input('Enter coefficient b: ');
c = input('Enter coefficient c: ');

delta = b^2 - 4*a*c;

if delta > 0

x1 = (-b + sqrt(delta))/(2*a);
x2 = (-b - sqrt(delta))/(2*a);
fprintf('The equation has two distinct real
roots: %f and %f\n', x1, x2);
elseif delta == 0
x = -b/(2*a);
fprintf('The equation has one real root
(double root): %f\n', x);
else

fprintf('The equation has no real roots.\n');


end

%output:

Enter coefficient a:

Enter coefficient b:

Enter coefficient c:
3

The equation has two distinct real roots:


-0.406930 and -1.843070

You might also like