0
votes

Matlab cannot give the 3d surface plot of the following program.Matlab gives the value of all the variables in matrix form. But it cacnot plot the 3d graph using surf command. Why matlab cannot plot a 3d graph using 'surf' command in symbolic variable?? pls help me....

clear all
close all
clc
syms r
c=1;
for R=0.01:0.01:0.03
    R1(c)=R;
    j=1;
    for l=0.3:0.01:0.4
        l1(j)=l;
        A=l*exp(-r^2);
        B=int(A,0,inf);
        B1(c,j)=B;
        j=j+1;
    end
    c=c+1;
end
B1=real(B1)
surf(R1,l1,B1')
1
Have you heard about the meshgrid function? It creates a grid which allows you to vectorize the code. Also it seems weird with a matrix of integrals in this particular case. Is that what you want? - patrik
@patrik thank u so much sir for ur help. but the 3d plot is not showing. - ARIJIT
I understand that, but I fear that there are more issues with this code and we need to attack them one-by-one. The first thing I felt important was to guide you to a function that have the main purpose to create a grid for the surf and mesh functions. I thought that by looking at this function you would understand how surf works. Next to understand why you calculate the same integral 3 times and then calculate it 30 times more with different offset. If this was solved all indexing problems that likely will appear from a loop, would go away. The symbol issue would still be there though... - patrik
What I mean is that the same result that you want could be achieved with about 5 or 6 lines, but then I am not sure if the code example tries to do exactly what you expect it to. This has also to do with that R seems quite random. R is not a part of the integral or any part of the code except plotting. Why integrate over r from 0 to inf and then plot it for R. It seems you tries to do something else. Is the main problem that you want to plot the integral of e^(-r^2) for the values of R1 and l1or do you even want to plot e^(-(x^2+y^2))? - patrik

1 Answers

0
votes

You just need to add these three lines after the last end:

B1=double(B1)               % Converts from symbolic to numerical
[X ,Y]=meshgrid(R1,l1);     % Creates a grid that is R1,l1 size, repeated
surf(R1,l1,B1')             % plot!

enter image description here