# MATLAB intro exercise

a =

1.0000 2.0000 -1.0000 1.0000 0.8333 4.5000

>> a=[1 2 -1 1 5/6 4.5]; %qyadratic eqn coeffts with

>> b=[-1 -14 0 -6 -4 -12.15]

b =

-1.0000 -14.0000 0 -6.0000 -4.0000 -12.1500

>> c= [-2 24 -1 10 4.8 8.1]

c =

-2.0000 24.0000 -1.0000 10.0000 4.8000 8.1000

>> n= length(a)

n =

6

>> for m=1:n

end

solution for eqn

1

disc =

9

x1 =

2

x2 =

-1

solution for eqn

2

disc =

4

x1 =

4

x2 =

3

solution for eqn

3

disc =

-4

no real roots

solution for eqn

4

disc =

-4

no real roots

solution for eqn

5

disc =

0

x1 =

2.4000

x2 =

2.4000

solution for eqn

6

disc =

1.8225

x1 =

1.5000

x2 =

1.2000

>>

>> disc=zeros(1,n); x1=disc; x2=disc

x2 =

0 0 0 0 0 0

>> disc(m)

ans =

0

>> x1(m)

ans =

0

>> X=[1 3 -5 -1]';

>> A=[-2 1 00; 3 4 7 -2; 1 0 0 1; 6 7 -2 0; 5 3 1 0];

??? Error using ==> vertcat

CAT arguments dimensions are not consistent.

>> A=[-2 1 0 0; 3 4 7 -2; 1 0 0 1; 6 7 -2 0; 5 3 1 0];

>> [m n]= size(A);

>> Y=zeroes(5,1);

??? Undefined function or method 'zeroes' for input arguments of type 'double'.

>> Y=zeros(5,1);

>> for k =1:m

for l=1:n

Y(k)=Y(k)+A(k,l)*X(l);

end

end

>> Y

Y =

1

-18

0

37

9

>> disp('Expected answer is:')

Expected answer is:

>> Y1=A*X

Y1 =

1

-18

0

37

9

>> N=100;K=17;

>> n=N; found=0;

>> while found==0

if mod(n,K)==0

found=1;

else

n=n-1;

end

end

>> help mod

MOD Modulus after division.

MOD(x,y) is x - n.*y where n = floor(x./y) if y ~= 0. If y is not an integer and the quotient x./y is within roundoff error of an integer, then n is that integer. The inputs x and y must be real arrays of the same size, or real scalars.

The statement "x and y are congruent mod m" means mod(x,m) == mod(y,m).

By convention:

MOD(x,0) is x.

MOD(x,x) is 0.

MOD(x,y), for x~=y and y~=0, has the same sign as y.

Note: REM(x,y), for x~=y and y~=0, has the same sign as x. MOD(x,y) and REM(x,y) are equal if x and y have the same sign, but differ by y if x and y have different signs.

See also rem.

Overloaded methods:

codistributed/mod

sym/mod

Reference page in Help browser

doc mod

>> qwwe

>> qwwe.m

??? Undefined variable "qwwe" or function "qwwe.m".

>> myemail='assel_nugmanmail.ru'

myemail =

assel_nugmanmail.ru

>> length(myemail)

ans =

19

>> substrings(myemail)

??? Undefined function or method 'substrings' for input arguments of type 'char'.

>> substring(myemail)

??? Undefined function or method 'substring' for input arguments of type 'char'.

>> module='MATH286: Numerical & Statistical Analysis with Programming'

module =

MATH286: Numerical & Statistical Analysis with Programming

>> nchars=length(module)

nchars =

58

>> code=module(1:7)

code =

MATH286

>> words='The module is'

words =

The module is

>> words=[words code]

words =

The module isMATH286

>> sbegin='1234'

sbegin =

1234

>> smore='5678'

smore =

5678

>> snew=strcat(sbegin,smore)

snew =

12345678

>> smore=[sbegin smore]

smore =

12345678

>> smore=[sbegin,smore]

smore =

123412345678

>> smore=[sbegin smore]

smore =

1234123412345678

>> clear

>> sbegin='1234'

sbegin =

1234

>> smore='5678'

smore =

5678

>> smore=[sbegin smore]

smore =

12345678

>> snew=strcat(sbegin,smore)

snew =

123412345678

>> if strcmp(snew,smore) disp ('these are the same');

else disp('these are not the same'); end

these are not the same

>>...

Please join StudyMode to read the full document