I am trying to solve a non-linear equation. In the matlab program, I'm stuck up.

34 Views Asked by At

One of the problems could be that, I want a matrix of order 33 but the output is 44, with first row and first column consisting of zeros. Can someone help !

n=5; m=5; T=1; for i=2:n-1 for q=2:m-1 uexact(i,q,T)=exp(i+q-3*T);

end

end

uexact =

     0         0         0         0
     0    2.7183    7.3891   20.0855
     0    7.3891   20.0855   54.5982
     0   20.0855   54.5982  148.4132
1

There are 1 best solutions below

6
On

Use

$uexact(i-1,q-1,T)=exp(i+q-3*T);$

instead. Even though your original code does only assign values to columns 2-5 and rows 2-5, Matlab automatically assumes that there must be a column 1 and row 1 to which it assigns 0 as a default value.