MATLAB Answers

Xinhua
0

fsurf not drawing cant explain

Asked by Xinhua
on 29 Apr 2019
Latest activity Commented on by David Wilson on 30 Apr 2019
Try these script below
clear
syms x y z;
f1= 0.594693*x - 0.037385*y - 4.415084e-48*(1.410081e94*x^2 - 1.010367e94*x*y - 7.167399e96*x - 6.594237e94*y^2 + 4.505749e95*y + 8.942503e98)^(1/2) - 26.520424;
f2= 0.594693*x - 0.037385*y + 4.415084e-48*(1.410081e94*x^2 - 1.010367e94*x*y - 7.167399e96*x - 6.594237e94*y^2 + 4.505749e95*y + 8.942503e98)^(1/2) - 26.520424;
fsurf(f1,'FaceColor','red')
hold on
fsurf(f2,'FaceColor','green')
hold off
xlabel('x');
ylabel('y');
zlabel('z');
It produce empty drawing.there are some big numbers in the equation but the final value should be within +-200.No reason it doesn't draw.

  0 Comments

Sign in to comment.

Tags

Products

1 Answer

Answer by David Wilson on 29 Apr 2019
Edited by David Wilson on 29 Apr 2019

Do you really need to use the symbolic toolbox? Why not just plot a numerical surface? But you are right, your numbers are widely varying and your surfaces are fairly flat.
Below I just took arbitrary ranges.
clear
f1= @(x,y) 0.594693*x - 0.037385*y - 4.415084e-48*(1.410081e94*x.^2 - 1.010367e94*x.*y - 7.167399e96*x - ...
6.594237e94*y.^2 + 4.505749e95*y + 8.942503e98).^(1/2) - 26.520424;
f2= @(x,y) 0.594693*x - 0.037385*y + 4.415084e-48*(1.410081e94*x.^2 - 1.010367e94*x.*y - 7.167399e96*x - ...
6.594237e94*y.^2 + 4.505749e95*y + 8.942503e98).^(1/2) - 26.520424;
xv = linspace(-2,2,20)'; yv = linspace(-3,5,30)';
[X,Y] = meshgrid(xv,yv)
F1 = f1(X,Y);
F2 = f2(X,Y);
surf(xv, yv, F1)
hold on
surf(xv, yv, F2)
hold off

  2 Comments

the problem is if I took the range too wide it will produce complex number and it will not draw either and I cant manuelly calculate ranges for every graph I draw.A corret image should produce a cone shape.untitled.jpg
One ugly solution is to identify where the complex regions are and then "NaN" them.
It's not overly pretty this way, but can be made better with a finer grid. You could always try fimplicit3 if not satisfied.
clear
f1= @(x,y) 0.594693*x - 0.037385*y - 4.415084e-48*(1.410081e94*x.^2 - 1.010367e94*x.*y - 7.167399e96*x - ...
6.594237e94*y.^2 + 4.505749e95*y + 8.942503e98).^(1/2) - 26.520424;
f2= @(x,y) 0.594693*x - 0.037385*y + 4.415084e-48*(1.410081e94*x.^2 - 1.010367e94*x.*y - 7.167399e96*x - ...
6.594237e94*y.^2 + 4.505749e95*y + 8.942503e98).^(1/2) - 26.520424;
% Now use a wide range
yv = linspace(-300,400,150)';
xv = linspace(-300,-120,130)';
[X,Y] = meshgrid(xv,yv)
F1 = f1(X,Y);
F2 = f2(X,Y);
F1(find(imag(F1)~=0)) = NaN; % drop complex parts
F2(find(imag(F2)~=0)) = NaN;
%
surf(xv, yv, real(F1))
hold on
surf(xv, yv, real(F2))
hold off
shading interp
lighting phong
camlight left
tmp.png

Sign in to comment.