็็Have a question about plot graph

1 visualización (últimos 30 días)
Ratchapon Nilprapa
Ratchapon Nilprapa el 20 de Dic. de 2021
Comentada: Walter Roberson el 20 de Dic. de 2021
I'm new to Matlab program, I want to plot mesh 3D graph but this code have a problem in "mesh(T,Cs,x)" please give any advise to me.
Thank you
%Graph 1
T=[873:100:1073];
Cs=[0.15 0.30 0.45];
[T,Cs]=meshgrid(T,Cs);
mesh(T,Cs,x)
Unrecognized function or variable 'x'.
Ylabel('length Carbon can diffuse(cm)','fontsize',18);
Xlabel('temperature (°C)','fontsize',18);
Zlabel('CarbonStart ,fontsize',18);
  3 comentarios
Ratchapon Nilprapa
Ratchapon Nilprapa el 20 de Dic. de 2021
Editada: Walter Roberson el 20 de Dic. de 2021
Yes, but 'x' value is found from the equation on the line above (x = z .* scalingFactor;).
this is all of my code
%%input parameter%%
R=8.314;
T=[873:100:1073];%%%K
Cs=[15 30 45];%%Carbon at surface
Cx=0.12;
C0= 0.08;%Carbon in specimen
t=3600;% sec
% find diffusion coefficients
D=-0.27*(1.04/-0.22)*exp((-246)./(R*T)); %(unit: cm^2*sec^-1)
% use D to find how far that carbon can diffusion
Erf = (Cs-Cx)./(Cs-C0);
z=NaN(size(Erf));
scalingFactor = 2*sqrt(D*t);
for n = 1 : numel(Erf)
if Erf(n)<2
z(n)=(-0.3725*Erf(n)^2)+(1.2144*(Erf(n)))+(0.0006);%error(0.01-0.08%) 0.4286
else
z(n)=(-0.0109*Erf(n)^2)+(0.0577*(Erf(n)))+(0.9235);%error(<0.01%)
end
%find X6
x = z .* scalingFactor; %%% ***t=3600***
end
%Graph 1
T=[873:100:1073];
Cs=[0.15 0.30 0.45];
[T,Cs]=meshgrid(T,Cs);
mesh(T,Cs,x)
Error using mesh (line 71)
Z must be a matrix, not a scalar or vector.
Ylabel('length Carbon can diffuse(cm)','fontsize',18);
Xlabel('temperature (°C)','fontsize',18);
Zlabel('CarbonStart ,fontsize',18);
Walter Roberson
Walter Roberson el 20 de Dic. de 2021
Cs=[15 30 45];%%Carbon at surface
Vector.
Cx=0.12;
C0= 0.08;%Carbon in specimen
scalar and scalar
Erf = (Cs-Cx)./(Cs-C0);
vector minus scalar is vector, vector minus scalar is vector, vector ./ vector with the same orientation gives a vector result, so Erf is a vector.
z=NaN(size(Erf));
So z will be initialized as a vector.
for n = 1 : numel(Erf)
if Erf(n)<2
z(n)=(-0.3725*Erf(n)^2)+(1.2144*(Erf(n)))+(0.0006);%error(0.01-0.08%) 0.4286
else
z(n)=(-0.0109*Erf(n)^2)+(0.0577*(Erf(n)))+(0.9235);%error(<0.01%)
end
%find X6
Scalar entries of z are assigned to, so z remains a vector.
x = z .* scalingFactor; %%% ***t=3600***
all of x is being overwritten each time. The right hand side uses all of z, including the entries that are still nan because they have not been written to yet, so x will be set as something the same size as z, so x will be a vector.
T=[873:100:1073];
Cs=[0.15 0.30 0.45];
[T,Cs]=meshgrid(T,Cs);
After that, T and Cs will be 2D grids that are 3 x 3.
mesh(T,Cs,x)
T is 3x3, Cs is 3x3, x is a vector the same size as z which is the same size as Erf which is the same size as the earlier meaning of Cs.
Note by the way that the earlier Cs uses 15, 30, 45, but the new Cs uses 0.15, 0.30, 0.45, which is 100 times smaller. Using that as coordinates for a plot is misleading, as the calculation was done in terms of the larger-scale Cs.
You are plotting x as if it depends upon T (temperature), but nothing in your calculation uses temperature.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by