how to use mesh to plot 3D image?

6 vues (au cours des 30 derniers jours)
M.Rameswari Sudha
M.Rameswari Sudha le 12 Jan 2023
I couldnt get mesh instead of plot3. help anyone.
clc
clear all
u1=4;u2=8;a=30;b=5;a2=100;A=500;c2=10;c3=12;c4=8;D0=115; b2=0.2;
a=0.01;d=0.2;m=0.5;k1=0.5;k0=1;k2=2;
c1=5;
t1= 0.2 : 0.2 :1.8
T=0.2 : 0.2 :1.8
n=length(t1)
j=1;
for i=1:n
TC=(1./T(i)).*(c1.*((b-a)-b.*t1(i)-(a+b.*(1+m)./(1+m-t1(i))))+c2.*(b.*t1(i)-(a+b.*(1+m)).*(t1(i)./(1+m-t1(i))))+c3.*((a./k1)-((b./k1.^2).*(1-k1.*T(i))).*(((-u1.*k1)./(1+k1.*(t1(i)-T(i)))+1)-((1-k1.*T(i))./(1+k1.*(t1(i)-T(i))))+(b.*k0.*(t1(i)-u1)./k1)-(a-(b.*k0.*(1-k1.*T(i))./k1)).*((u2-u1)./(1+k1.*(t1(i)-T(i))))+(k0.*D0./k1).*((k1.*(u1-u2)./(1+k1.*(t1(i)-T(i))))-(a-(b.*k0./k1).*(1-k1.*T(i))).*((T(i)-k2)./(1+k1.*(t1(i)-T(i))))+(b.*k0./k1).*(u2-T(i))-(1-k1.*T(i)).*((T(i)+u2)./(1+k1.*(t1(i)-T(i))))+c4.*(-a2+b2.*t1(i)+k0.*(a-(b./k1).*(1-k1.*T(i)).*(1./(1+k1.*(t1(i)-T(i)))+(b./k1))))))));
%TC=(a/T(i))*((A/a)+(h/(th+b))*(((th+b)*(exp(-R*td)-1)/(b*R))+(1/(b+R))*(exp(b*td)-exp(-R*td))*(exp((th+b)*(t1(i)-td))+(th/b)))+((h)/(th+b))*((1/R)*(exp(-R*t1(i))-exp(-R*td))+(1/(th+b+R))*(exp((th+b)*(t1(i)-td)-(R*td))-exp(-R*t1(i))))+((s*del)/(R^2))*(exp(-R*t1(i))-exp(-R*T(i))*(R*(T(i)-t1(i))+1))+(pi*(1-del)/R)*(exp(-R*t1(i))-exp(-R*T(i)))+p*((1/(th+b))*(exp((th+b)*(t1(i)-td))-1)*exp(b*td)+(1/b)*(exp(b*td)-1)+del*exp(-R*T(i))*(T(i)-t1(i))));
z(j)=TC;
j=j+1;
end
% t1,
%
% T
% z
length(T);
length(z);
mesh(t1,T,z(t1,T))
axis square; grid on
% (a/x(1))*(exp(-R*x(1))*s*del*(x(1)-x(2))+exp(-R*x(1))*pi*(1-del)+p*del*exp(-R*x(1))*(1-R*(x(1)-x(2))))-(a/(x(1)^2))*((A/a)+(h/(th+b))*(((th+b)*(exp(-R*td)-1)/(b*R))+(1/(b+R))*(exp(b*td)-exp(-R*td))*(exp((th+b)*(x(2)-td))+(th/b)))+((h)/(th+b))*((1/R)*(exp(-R*x(2))-exp(-R*td))+(1/(th+b+R))*(exp((th+b)*(x(2)-td)-(R*td))-exp(-R*x(2))))+((s*del)/(R^2))*(exp(-R*x(2))-exp(-R*x(1))*(R*(x(1)-x(2))+1))+(pi*(1-del)/R)*(exp(-R*x(2))-exp(-R*x(1)))+p*((1/(th+b))*(exp((th+b)*(x(2)-td))-1)*exp(b*td)+(1/b)*(exp(b*td)-1)+del*exp(-R*x(1))*(x(1)-x(2))))
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in totalcost (line 23)
mesh(t1,T,z(t1,T))

Réponse acceptée

Karim
Karim le 12 Jan 2023
I assume you want to create a 3d surf plot? You can use the method below.
u1=4;u2=8;a=30;b=5;a2=100;A=500;c2=10;c3=12;c4=8;D0=115;b2=0.2;
a=0.01;d=0.2;m=0.5;k1=0.5;k0=1;k2=2;c1=5;
t1 = 0.2:0.2:1.8;
t2 = 0.2:0.2:1.8;
[X,Y] = meshgrid(t1,t2);
Z = zeros(size(X));
for i = 1:numel(X)
t1_i = X(i);
t2_i = Y(i);
Z(i) = (1./t2_i).*(c1.*((b-a)-b.*t1_i-(a+b.*(1+m)./(1+m-t1_i)))+c2.*(b.*t1_i-(a+b.*(1+m)).*(t1_i./(1+m-t1_i)))+c3.*((a./k1)-((b./k1.^2).*(1-k1.*t2_i)).*(((-u1.*k1)./(1+k1.*(t1_i-t2_i))+1)-((1-k1.*t2_i)./(1+k1.*(t1_i-t2_i)))+(b.*k0.*(t1_i-u1)./k1)-(a-(b.*k0.*(1-k1.*t2_i)./k1)).*((u2-u1)./(1+k1.*(t1_i-t2_i)))+(k0.*D0./k1).*((k1.*(u1-u2)./(1+k1.*(t1_i-t2_i)))-(a-(b.*k0./k1).*(1-k1.*t2_i)).*((t2_i-k2)./(1+k1.*(t1_i-t2_i)))+(b.*k0./k1).*(u2-t2_i)-(1-k1.*t2_i).*((t2_i+u2)./(1+k1.*(t1_i-t2_i)))+c4.*(-a2+b2.*t1_i+k0.*(a-(b./k1).*(1-k1.*t2_i).*(1./(1+k1.*(t1_i-t2_i))+(b./k1))))))));
end
figure
surf(X,Y,Z)
view([135 45])
grid on
  1 commentaire
M.Rameswari Sudha
M.Rameswari Sudha le 12 Jan 2023
Thank you so much. I got the answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by