Problem plotting a 3-D function

조회 수: 1 (최근 30일)
Ben
Ben 2013년 5월 16일
Hi there
I need to plot 2 3-D functions an see how they intersect. However I am experiencing problems with one of the functions (z1). Apparently i am calculating it wrong, therefor my input for z1 is wrong. Can somebody help me? This should be rather easy for someone with experience ;)
This is the code:
% Define the input grid
clc, clear, close all
[x, y] = meshgrid(linspace(0,400,40),linspace(0,30000,40));
grid on
xlabel('Stress [MPa]')
ylabel('Time [h]')
zlabel('Creep Strain [-]')
% Calculate the two surfaces
A1 = -8.269000000000000;
m1 = 2.071000000000000;
m2 = 0.239700000000000;
B1 = -13.100000000000000;
n1 = 2.813000000000000;
B2 = -49.960000000000001;
n2 = 18.170000000000002;
z1 = 10^A1*x.^m1*y.^m2+y.*(10^B1*x.^n1+10^B2*x.^n2);
z2 = 0*x+0*y+0.01;
% Visualize the two surfaces
surface(x, y, z1, 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none');
surface(x, y, z2, 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none');
view(3); camlight; axis vis3d

답변 (2개)

David Sanchez
David Sanchez 2013년 5월 16일
try to hold on the current figure and change your point of view:
% Define the input grid clc, clear, close all
[x, y] = meshgrid(linspace(0,400,40),linspace(0,30000,40));
grid on
xlabel('Stress [MPa]')
ylabel('Time [h]')
zlabel('Creep Strain [-]')
% Calculate the two surfaces
A1 = -8.269000000000000;
m1 = 2.071000000000000;
m2 = 0.239700000000000;
B1 = -13.100000000000000;
n1 = 2.813000000000000;
B2 = -49.960000000000001;
n2 = 18.170000000000002;
z1 = 10^A1*x.^m1*y.^m2+y.*(10^B1*x.^n1+10^B2*x.^n2);
z2 = 0*x+0*y+0.01;
% Visualize the two surfaces
surface(x, y, z1, 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none'); hold on
surface(x, y, z2, 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none'); hold off
view([30,30]);
camlight;
axis vis3d
  댓글 수: 3
David Sanchez
David Sanchez 2013년 5월 16일
Is your z1 function this one?
z1 = (10^A1).*(x.^m1).*(y.^m2) + y.*( (10^B1).*(x.^n1) + (10^B2).*(x.^n2) );
Since we don't know your function, there is no way to help you further. Could you be more specific?
Ben
Ben 2013년 5월 16일
yes that is the function z1! if you for example enter x = 1 and y = 1 you will get other results for z1(1,1) then i you use meshgrid and linspace to define x and y

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


David Sanchez
David Sanchez 2013년 5월 16일
Well, I think you are having a scale issue. Your z1 is right, and the way to plot your data as well is right, but bear in mind the scale of your result ( z1 ). You are plotting an exponential function, and as such, there will be a big difference in the results you obtain with an insignificant change of your input values. I figure out you know that your z2 is just a plane on z=0.01. Make sure your z1 is exactly what you want.
  댓글 수: 2
Ben
Ben 2013년 5월 16일
편집: Ben 2013년 5월 16일
I know what you are thinking, but have a look at this. If i enter
input: x = 1; y = 1; z1 = 10^A1*x.^m1*y.^m2+y.*(10^B1*x.^n1+10^B2*x.^n2);
output: z1 = 5.382777257986354e-009
However if I enter
Input: [x, y] = meshgrid(linspace(0,400,400),linspace(0,10,400)); z1 = 10^A1*x.^m1*y.^m2+y.*(10^B1*x.^n1+10^B2*x.^n2); smallestvalue = min(min(z1));
output: smallestvalue = 1.887491724543205
So you can see there is definitely an error while calculating the function z1, I just do not know what I am doing wrong
Iain
Iain 2013년 5월 16일
Its a case of garbage in, garbage out.
Check that your x and y values output by meshgrid include (1,1). I suspect you'll need to change it to linspace(0,400,401) and linspace(0,10,401)

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by