You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How can I plot 3D surface x^3 + y^3 + z^3 = 1, where x, y, z are in unit closed interval in MATLAB ?.
8 views (last 30 days)
Show older comments
I want to plot a surface x^3 + y^3 + z^3 = 1, where x, y, z are in unit closed interval. The MATLAB is not displaying the plot. Perhaps there occur some complex roots. Please help me to write its code. Thanks in advance.
Accepted Answer
madhan ravi
on 11 Nov 2018
Edited: madhan ravi
on 11 Nov 2018
syms x y z
fimplicit3(x^3+y^3+z^3==1,[-1 1 -1 1 -1 1])
11 Comments
Amna Habib
on 11 Nov 2018
Edited: madhan ravi
on 11 Nov 2018
---------------------------------------------------------------------------------------------
MATLAB Version: 8.5.0.197613 (R2015a)
MATLAB License Number: ••••••
Operating System: Microsoft Windows 8.1 Pro Version 6.3 (Build 9600)
Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) Client VM mixed mode
---------------------------------------------------------------------------------------------
MATLAB Version 8.5 (R2015a)
Simulink Version 8.5 (R2015a)
Communications System Toolbox Version 6.0 (R2015a)
Computer Vision System Toolbox Version 6.2 (R2015a)
Control System Toolbox Version 9.9 (R2015a)
Curve Fitting Toolbox Version 3.5.1 (R2015a)
DO Qualification Kit Version 2.5 (R2015a)
DSP System Toolbox Version 9.0 (R2015a)
Data Acquisition Toolbox Version 3.7 (R2015a)
Database Toolbox Version 5.2.1 (R2015a)
Datafeed Toolbox Version 5.1 (R2015a)
Econometrics Toolbox Version 3.2 (R2015a)
Embedded Coder Version 6.8 (R2015a)
Filter Design HDL Coder Version 2.9.7 (R2015a)
Financial Instruments Toolbox Version 2.1 (R2015a)
Financial Toolbox Version 5.5 (R2015a)
Fixed-Point Designer Version 5.0 (R2015a)
Fuzzy Logic Toolbox Version 2.2.21 (R2015a)
Gauges Blockset Version 2.0.9 (R2015a)
Global Optimization Toolbox Version 3.3.1 (R2015a)
HDL Coder Version 3.6 (R2015a)
HDL Verifier Version 4.6 (R2015a)
IEC Certification Kit Version 3.5 (R2015a)
Image Acquisition Toolbox Version 4.9 (R2015a)
Image Processing Toolbox Version 9.2 (R2015a)
Instrument Control Toolbox Version 3.7 (R2015a)
LTE System Toolbox Version 2.0 (R2015a)
MATLAB Coder Version 2.8 (R2015a)
MATLAB Compiler Version 6.0 (R2015a)
MATLAB Compiler SDK Version 6.0 (R2015a)
MATLAB Distributed Computing Server Version 6.6 (R2015a)
MATLAB Report Generator Version 4.1 (R2015a)
Mapping Toolbox Version 4.1 (R2015a)
Model Predictive Control Toolbox Version 5.0.1 (R2015a)
Model-Based Calibration Toolbox Version 4.8.1 (R2015a)
Neural Network Toolbox Version 8.3 (R2015a)
OPC Toolbox Version 3.3.3 (R2015a)
Optimization Toolbox Version 7.2 (R2015a)
Parallel Computing Toolbox Version 6.6 (R2015a)
Partial Differential Equation Toolbox Version 2.0 (R2015a)
Phased Array System Toolbox Version 3.0 (R2015a)
Polyspace Bug Finder Version 1.3 (R2015a)
Polyspace Code Prover Version 9.3 (R2015a)
Robotics System Toolbox Version 1.0 (R2015a)
Robust Control Toolbox Version 5.3 (R2015a)
Signal Processing Toolbox Version 7.0 (R2015a)
SimElectronics Version 2.7 (R2015a)
Simscape Version 3.13 (R2015a)
Spreadsheet Link EX Version 3.2.3 (R2015a)
Stateflow Version 8.5 (R2015a)
Statistics and Machine Learning Toolbox Version 10.0 (R2015a)
Symbolic Math Toolbox Version 6.2 (R2015a)
System Identification Toolbox Version 9.2 (R2015a)
SystemTest Version 2.6.9 (R2015a)
Trading Toolbox Version 2.2 (R2015a)
Vehicle Network Toolbox Version 2.4 (R2015a)
Vision HDL Toolbox Version 1.0 (R2015a)
Wavelet Toolbox Version 4.14.1 (R2015a)
madhan ravi
on 11 Nov 2018
I suggest you to upgrade to 2016b or later because fimplicit3 was introduced in 2016b see https://www.mathworks.com/help/matlab/release-notes.html?rntext=fimplicit3&startrelease=R2015a&endrelease=R2018b&groupby=release&sortby=descending&searchHighlight=
Amna Habib
on 11 Nov 2018
Ok Thanks. But this is not an implicit function ever. Can you tell another command instead fimplicit3 for my version.
madhan ravi
on 11 Nov 2018
"But this is not an implicit function ever
It is! you need to know the difference between implicit and explicit function first before plotting.
x^2+y^2=1 is an implicit function
x=+-sqrt(1-x^2) is an explicit function
"Can you tell another command instead fimplicit3 for my version."
without this function I suspect it would be hard to construct the surface
Bruno Luong
on 11 Nov 2018
Edited: madhan ravi
on 11 Nov 2018
Thanks
madhan ravi's reply: Anytime :) @Bruno
More Answers (1)
Bruno Luong
on 11 Nov 2018
[x,y,z]=ndgrid(linspace(-1,1,33));
v=x.^3+y.^3+z.^3-1;
close all
p = patch(isosurface(x,y,z,v,0));
p.FaceColor = 'red';
daspect([1 1 1])
view(120,-30);
axis tight
camlight
lighting gouraud
15 Comments
madhan ravi
on 11 Nov 2018
cool @Bruno may I know how did you attach your image as an image instead of an attachment , I don't know how to attach an image not being an attachment?
Bruno Luong
on 11 Nov 2018
Edited: Bruno Luong
on 11 Nov 2018
I use the button "image" on the left of "attach file" button.
Amna Habib
on 11 Nov 2018
Very nice. I need this surface only in first octant, that is, all x, y and z varies from 0 to 1. Is only this change is require for it? [x,y,z]=ndgrid(linspace(0,1,33)) I am not expert in MATLAB till now.
Amna Habib
on 11 Nov 2018
Please find attached file. I want to compare the spaces covered by respective surfaces. They are not clear yet. How can I remove their mesh?
Bruno Luong
on 11 Nov 2018
To remove the mesh set
h.LineStyle = 'none';
[x,y,z]=ndgrid(linspace(-1,1,65));
close all
ptab = [1 1.5 2 3 4];
for k=1:length(ptab)
p = ptab(k);
v = abs(x).^p+abs(y).^p+abs(z).^p-1;
subplot(2,2,k);
h = patch(isosurface(x,y,z,v,0));
h.FaceColor = 'red';
h.LineStyle = 'none';
daspect([1 1 1])
view(75,20);
axis tight
camlight
lighting gouraud
title(sprintf('Sphere in l_{%g}', p));
end
Amna Habib
on 26 Jul 2022
i need help in plotting the function 'g'. Can you please correct this code.
I would be very thankful to you.
x = linspace(0, 1 );
f = @(x) (x<0.5) .* (7-3.* sqrt(-2.* (log(2.*x)))) + (x>=0.5).*(7+2.* sqrt(-2.* (log(2-(2.*x)))));
g = @(x) (x<0.5).* (7-5.* sqrt(-1.* (log(2-(2.*x))))) + (x>=0.5).*(7+4.* sqrt(-1.* (log(2.*x))));
figure
plot(x, [f(x); g(x)], 'linewidth', 1.5 )
Warning: Imaginary parts of complex X and/or Y arguments ignored.
Les Beckham
on 26 Jul 2022
Edited: Les Beckham
on 26 Jul 2022
It depends on what you really want to plot. g(x) is complex. In a 2d plot you can't plot a complex vector against a real vector. So, you have a few choices (ignoring f(x) which seems to be plotting just fine):
x = linspace(0, 1 );
g = @(x) (x<0.5).* (7-5.* sqrt(-1.* (log(2-(2.*x))))) + (x>=0.5).*(7+4.* sqrt(-1.* (log(2.*x))));
figure
plot(g(x), 'linewidth', 1.5) % plot the imaginary part of g(x) against the real part
xlabel 'real(g(x))'
ylabel 'imag(g(x))'
grid on
figure
plot(x, abs(g(x)), 'linewidth', 1.5) % plot the magnitudes of g(x) against x
xlabel 'x'
ylabel 'abs(g(x))'
grid on
figure
plot(x, angle(g(x)), 'linewidth', 1.5) % plot the phase angles of g(x) against x
xlabel 'x'
ylabel 'angle(g(x))'
grid on
figure
% plot the real part of g(x) against x; note that this is what you got
% above, plot defaults to plotting the real part and throws away the
% imaginary part
plot(x, real(g(x)), 'linewidth', 1.5)
xlabel 'x'
ylabel 'real(g(x))'
grid on
figure
plot(x, imag(g(x)), 'linewidth', 1.5) % plot the imaginary part of g(x) against x
xlabel 'x'
ylabel 'imag(g(x))'
grid on
Amna Habib
on 26 Jul 2022
Thanks a lot @Les Beckham
I got this point. I appreciate your effort. Well explained!
Amna Habib
on 26 Jul 2022
if you feel easy please check this code too. This function is very simple but graph is different as compared to my manual calculations.
Thank you very much for your kindness!
x = linspace(0, 1 ).';
f = @(x) (x<0.5) .* (30.*x) + (x>=0.5).* (70.*x)-20 ;
g = @(x) (x<0.5).* 30.*(1-x) + (x>=0.5).* 50-(70.*x ) ;
figure
plot(x, [f(x), g(x)], 'linewidth', 1.5 )
Torsten
on 26 Jul 2022
Maybe you mean
x = linspace(0, 1,100 ).';
f = @(x) (x<0.5) .* (30.*x) + (x>=0.5).* (70.*x-20 );
g = @(x) (x<0.5).* (30.*(1-x)) + (x>=0.5).* (50-70.*x ) ;
figure
plot(x, [f(x), g(x)], 'linewidth', 1.5 )
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)