필터 지우기
필터 지우기

how to plot a symbolic equation with 4 variables?

조회 수: 8 (최근 30일)
Alex
Alex 2013년 4월 1일
Does anyone know how to plot a symbolic equation containing 4 variables? u=f(x,y,z) using colour as the fourth dimension for u?
Thanks a lot!

채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 1일
Assuming that f is a symbolic expression in x, y, z, then:
ufun = matlabFunction(f, 'vars', {'x', 'y', 'z'});
xrange = linspace(-10, 10, 50); %for example
yrange = linspace(-pi, 3*pi/2, 50); %for example
zrange = linspace(1, 2, 57); %for example
[X, Y, Z] = ndgrid(xrange, yrange, zrange);
u = ufun(X, Y, Z);
pointsize = 10; %adjust as needed
scatter3(X, Y, Z, pointsize, u);
colormap(copper(256)); %choose appropriate colormap
  댓글 수: 2
Alex
Alex 2013년 4월 1일
편집: Walter Roberson 2013년 4월 1일
thanks for your helping hand, thanks to your reply I managed to figure out how to work with in N-D using ndgrid but I have one error puzzling me, can you help here?
[X, Y, Z] = ndgrid(1:200, 1:200, 1:200);
then I find U=...(omitted due to complexity)
scatter3(X,Y,Z,10,U)
and here the problem
Error using scatter3 (line 68)
X, Y and Z must be vectors of the same length.
it is strange because they were all created of equal length?
Walter Roberson
Walter Roberson 2013년 4월 1일
scatter3(X(:), Y(:), Z(:), 10, U(:))
Warning: this is pretty slow for 200 x 200 x 200! Expect slowdowns to start once you get bigger than about 21 x 21 x 21. On my system, 50 x 50 x 50 is still peppy "enough" to draw originally, but rotating it is becoming clumsy. 200 x 200 x 200 took on the order of a minute or more to draw -- even just closing the figure took a good 30 seconds.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by