How can I plot 3D surface x^3 + y^3 + z^3 = 1, where x, y, z are in unit closed interval in MATLAB ?.
3 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
syms x y z
fimplicit3(x^3+y^3+z^3==1,[-1 1 -1 1 -1 1])
11 个评论
Amna Habib
2018-11-11
编辑:madhan ravi
2018-11-11
---------------------------------------------------------------------------------------------
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
2018-11-11
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
2018-11-11
Ok Thanks. But this is not an implicit function ever. Can you tell another command instead fimplicit3 for my version.
madhan ravi
2018-11-11
"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
更多回答(1 个)
Bruno Luong
2018-11-11
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194703/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194704/image.png)
[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 个评论
madhan ravi
2018-11-11
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
2018-11-11
编辑:Bruno Luong
2018-11-11
I use the button "image" on the left of "attach file" button.
Amna Habib
2018-11-11
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
2018-11-11
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
2018-11-11
To remove the mesh set
h.LineStyle = 'none';
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194723/image.png)
[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
2022-7-26
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1077915/image.png)
Les Beckham
2022-7-26
编辑:Les Beckham
2022-7-26
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078070/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078075/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078080/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078085/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078090/image.png)
Amna Habib
2022-7-26
Thanks a lot @Les Beckham
I got this point. I appreciate your effort. Well explained!
Amna Habib
2022-7-26
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 )
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078135/image.png)
Torsten
2022-7-26
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 )
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1078140/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)