I want to break down my 3d graph into 2d graphs.
1 view (last 30 days)
Show older comments
Hello Everyone,
I have a 3D derived graph. In this 3D graph, I want to obtain graphs such as x-z graph where y=constant and y-z graph where x=constant value. Additonal I want to take the derivatives of these graphs.
I leave the code below.
Thank you for your support.
T=273:1:420; %axisy
% x=0:0.1:10;
x = linspace(0, 0.35, 22);
Txm=1:1:148;
Txn=1.21:1:148.21;
Txmn=Txn-Txm; % X=0.21 (axis x measured first value)
Txk=1:1:148;
Txmk=Txk-Txm; % X=0; (axis x measured second value)
%lamda11=0.002547*(T.^2)+-0.01608*T+ 7162 ; %axis z(y) function
%lamda22=0.004723*(T.^2) +0.07403*T + 6962 ; %axis z(y) function
lamda__11= 0.00472 .*(T.^2)+0.0740 .*T+8.623e+03 %lamda %Eg(0)
lamda__44= 0.00255 .*(T.^2)-0.0161 .*T+8.8230e+3 %lamda %Eg(0.21)
cmtx11 = [0.00255 -0.0161 8.8230e+3; 0.00472 0.0740 8.623e+03];
cmtx = cmtx11 ; % Parameter Matrix
for k = 1:size(cmtx,2)
DM = [0 1; 0.21 1]; % Design Matrix
Bx(:,k) = DM \ cmtx(:,k); % Linear Regression For Each Coefficient
Ck(:,k) = DM * Bx(:,k); % Check Results
end
% format longG
% Bx
% Ck
format shortE
lambdafcn = @(T,x) [x 1]*Bx(:,1).*(T.^2) + [x 1]*Bx(:,2).*T + [x 1]*Bx(:,3); % 'lambda' Function Incorporating Linear Regression Parameters For Each Coefficient
[xm,Tm] = ndgrid(x, T); % Create Matrices From Vectors
xv = xm(:);
Tv = Tm(:);
for k = 1:numel(xm)
lambdav(k,:) = lambdafcn(Tv(k),xv(k)); % Create Vector Of 'lambda' Values For 'scatteredInterpolant'
end
Fz = scatteredInterpolant(Tm(:), xm(:), lambdav); % Create Interpolation Function
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
x_07 = 0.07+zeros(size(T(:))); % Define 'x' Vector
Line_07 = Fz(T(:), x_07); % Interpolate Line
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
0 Comments
Accepted Answer
Star Strider
on 5 Jan 2024
Use ‘view(90,0)’ for the ‘x-z’ view, and ‘view(0,0)’ for the ‘y-z’ view.
I added both of those at the end of the original code —
T=273:1:420; %axisy
% x=0:0.1:10;
x = linspace(0, 0.35, 22);
Txm=1:1:148;
Txn=1.21:1:148.21;
Txmn=Txn-Txm; % X=0.21 (axis x measured first value)
Txk=1:1:148;
Txmk=Txk-Txm; % X=0; (axis x measured second value)
%lamda11=0.002547*(T.^2)+-0.01608*T+ 7162 ; %axis z(y) function
%lamda22=0.004723*(T.^2) +0.07403*T + 6962 ; %axis z(y) function
lamda__11= 0.00472 .*(T.^2)+0.0740 .*T+8.623e+03 %lamda %Eg(0)
lamda__44= 0.00255 .*(T.^2)-0.0161 .*T+8.8230e+3 %lamda %Eg(0.21)
cmtx11 = [0.00255 -0.0161 8.8230e+3; 0.00472 0.0740 8.623e+03];
cmtx = cmtx11 ; % Parameter Matrix
for k = 1:size(cmtx,2)
DM = [0 1; 0.21 1]; % Design Matrix
Bx(:,k) = DM \ cmtx(:,k); % Linear Regression For Each Coefficient
Ck(:,k) = DM * Bx(:,k); % Check Results
end
% format longG
% Bx
% Ck
format shortE
lambdafcn = @(T,x) [x 1]*Bx(:,1).*(T.^2) + [x 1]*Bx(:,2).*T + [x 1]*Bx(:,3); % 'lambda' Function Incorporating Linear Regression Parameters For Each Coefficient
[xm,Tm] = ndgrid(x, T); % Create Matrices From Vectors
xv = xm(:);
Tv = Tm(:);
for k = 1:numel(xm)
lambdav(k,:) = lambdafcn(Tv(k),xv(k)); % Create Vector Of 'lambda' Values For 'scatteredInterpolant'
end
Fz = scatteredInterpolant(Tm(:), xm(:), lambdav); % Create Interpolation Function
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
x_07 = 0.07+zeros(size(T(:))); % Define 'x' Vector
Line_07 = Fz(T(:), x_07); % Interpolate Line
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation — ‘x-z’ View')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
view(90, 0)
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation — ‘y-z’ View')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
view(0,0)
Use the print function with '-dpng' to save each of them as a separate image if that is what you want to do.
.
6 Comments
Star Strider
on 7 Jan 2024
As always, my pleasure!
Those plots look great! I did not completely understand all the plots you wanted, however I am happy that my code allowed you to get the necessary information from your data to plot them.
The only suggestion I have is that using gradient rather than diff for numerical differentiation is usually preferable, since gradient produces an output the same size as the input, while diff produces an output that is one element less in the dimnensions along which it operates. The gradient values are also more reliable.
More Answers (0)
See Also
Categories
Find more on Function Approximation and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!















