0% found this document useful (0 votes)
14 views

MATLAB

The document defines matrices M and N, sets variables a and b, and initializes vector u. It then uses a for loop to populate u with values from another vector v. Finally, it uses nested for loops to apply an iterative formula to populate the values of u.

Uploaded by

Sara
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

MATLAB

The document defines matrices M and N, sets variables a and b, and initializes vector u. It then uses a for loop to populate u with values from another vector v. Finally, it uses nested for loops to apply an iterative formula to populate the values of u.

Uploaded by

Sara
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

>> M=10;

>> N=10;
>> a=0.1;
>> b=0.1;
>> u(1,:)= [1 2 9 3 16 10 1 5 6 3];
>> v= [5 7 5 6 9 10 15 11 4];
>> i=0;
>> for i=2:10
u(i,:)= [v(i-1) zeros(1,9)];
end
>> u

u =

1 2 9 3 16 10 1 5 6 3
5 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0
10 0 0 0 0 0 0 0 0 0
15 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0

>> for n=2:N


for m=2:M
u(n,m)= a*u(n,m-1) +b*u(n-1,m);
end
end
>> u

u =

1.0000 2.0000 9.0000 3.0000 16.0000 10.0000 1.0000 5.0000


6.0000 3.0000
5.0000 0.7000 0.9700 0.3970 1.6397 1.1640 0.2164 0.5216
0.6522 0.3652
7.0000 0.7700 0.1740 0.0571 0.1697 0.1334 0.0350 0.0557
0.0708 0.0436
5.0000 0.5770 0.0751 0.0132 0.0183 0.0152 0.0050 0.0061
0.0077 0.0051
6.0000 0.6577 0.0733 0.0087 0.0027 0.0018 0.0007 0.0007
0.0008 0.0006
9.0000 0.9658 0.1039 0.0113 0.0014 0.0003 0.0001 0.0001
0.0001 0.0001
10.0000 1.0966 0.1200 0.0131 0.0015 0.0002 0.0000 0.0000
0.0000 0.0000
15.0000 1.6097 0.1730 0.0186 0.0020 0.0002 0.0000 0.0000
0.0000 0.0000
11.0000 1.2610 0.1434 0.0162 0.0018 0.0002 0.0000 0.0000
0.0000 0.0000
4.0000 0.5261 0.0669 0.0083 0.0010 0.0001 0.0000 0.0000
0.0000 0.0000

You might also like