0

I am trying to plot a 3D graph between 2 scalars and one matrix for each of its entries. On compiling it is giving me "Submatrix incorrectly defined" error on line 11. The code:

i_max= 3;
u = zeros(4,5);
a1 = 1;
a2 = 1;
a3 = 1;
b1 = 1;
hx = linspace(1D-6,1D6,13);
ht = linspace(1D-6,1D6,13);
for i = 1:i_max
    for j = 2:4
        u(i+1,j)=u(i,j)+(ht*(a1*u(i,j))+b1+(((a2*u(i,j+1))-(2*a2*u(i,j))+(a2*u(i,j-1)))*(hx^-2))+(((a3*u(i,j+1))-(a3*u(i,j-1)))*(0.5*hx^-1)));
        plot(ht,hx,u(i+1,j));
    end
end

Full error message:

-->exec('C:\Users\deba123\Documents\assignments and lecture notes\Seventh Semester\UGP\Scilab\Simulation1_Plot.sce', -1)
+(((a3*u(i,j+1))-(a3*u(i,j-1)))*(0.5*hx^-1)))
                                          !--error 15 
Submatrix incorrectly defined.
at line      11 of exec file called by :    
emester\UGP\Scilab\Simulation1_Plot.sce', -1

Please help.

deba123
  • 15
  • 5

1 Answers1

0

For a 3-dimensional figure, you need 2 argument vectors and a matrix for the function values. So I expanded u to a tensor. At every operation in your code, I added the current dimension of the term. Now, a transparent handling of you calculation is given. For plotting you have to use the plot3d (single values) or surf (surface) command. In a 3-dim plot, you want two map 2 vectors (hx,ht) with dim n and m to an scalar z. Therefore you reach a (nxm)-matrix with your results. Is this, what you want to do? Currently, you have 13 values for each u(i,j,:) - entry, but you want (13x13) for every figure. Maybe the eval3d-function can help you.

i_max= 3;
u = zeros(4,5,13);
a1 = 1;
a2 = 1;
a3 = 1;
b1 = 1;
hx = linspace(1D-6,1D6,13); // 1 x 13
ht = linspace(1D-6,1D6,13); // 1 x 13

for i = 1:i_max
    for j = 2:4
        u(i+1,j,:)= u(i,j)... 
                  + ht*(a1*u(i,j))*b1... // 1 x 13 
                  +(((a2*u(i,j+1)) -(2*a2*u(i,j)) +(a2*u(i,j-1)))*(hx.^-2))... // 1 x 13 
                  +(((a3*u(i,j+1))-(a3*u(i,j-1)))*(0.5*hx.^-1)) ... // 1 x 13   
                  + hx*ones(13,1)*ht; // added to get non-zero values
                  z = squeeze( u(i+1,j, : ))'; // 1x13

                  // for a 3d-plot: (1x13, 1x13, 13x13) 
                  figure()
                  plot3d(ht,hx, z'* z ,'*' ); //

    end
end
peng
  • 300
  • 1
  • 12