Matlab - Ayuda en GUI novato

 
Vista:
sin imagen de perfil
Val: 26
Ha aumentado su posición en 2 puestos en Matlab (en relación al último mes)
Gráfica de Matlab

Ayuda en GUI novato

Publicado por Luis (16 intervenciones) el 09/09/2019 01:01:10
Hola buen dia! Estoy trabajando en una interfaz en matlab para poder introducir ciertas caracteristicas de unm programa previo que tengo, el problema es que estoy completamente perdido, al momento he dado la forma que deberia tener el archivo (anexo imagen), sin embargo es lo unico que tengo. Anexo mi codigo (fuente) y el codigo de la interfaz. Lo que he estado haciendo es pegando todo en el call back del boton, al momento ha funcionado pero cuando llega al enunciado A=zeros(N,N) me marca un error de que es un uso incorrecto de zeros. Esa matriz es llenada por el programa segun los parametos de entrada que se introduzcan. Si alguien puede ayudarme estare muy agradecido.


Este es el codigo GUI


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
% --- Executes on button press in calcular.
function calcular_Callback(hObject, eventdata, handles)
% hObject    handle to calcular (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% propiedades del ambiente
Tamb = str2double( get(handles.Temperaturamb1, 'string') );    %Temperatura en grados 
h = str2double( get(handles.conveccion1, 'string') );   %Coeficiente de conveccion
 
% propiedades del material
ku = str2double( get(handles.Conductividad1, 'string') );   %Conductividad termica
densidad = str2double( get(handles.densidad1, 'string') );      %kilogramo/metro^3
Calorespec = str2double( get(handles.Calosrespe1, 'string') );     %Calor especifico 
omega = str2double( get(handles.Coeficientedila1, 'string') );     %Coeficiente de expansion termica /°C
moduloYoung = str2double( get(handles.Moduloyoung1, 'string') );    %Modulo de eslasticidad aluminio
 
% propiedades de la herramienta
diametroh = str2double( get(handles.diametro1, 'string') );              %Diametro de la herramienta en milimetros
profundidadh = str2double( get(handles.profundidad1, 'string') );                 %Profundidad de penetracion
 
%Datos de nodos y longitudes
Nx = str2double( get(handles.nodosx1, 'string') );    %Numero de nodos en X
Nz = str2double( get(handles.nodosz1, 'string') );    %Numero de nodos en Y
Ny = str2double( get(handles.nodosy1, 'string') );    %Numero de nodos en Z
Lx = str2double( get(handles.longx1, 'string') );    %Longitud en X en metros
Ly = str2double( get(handles.longy1, 'string') );    %Longitud en Y en metros
Lz = str2double( get(handles.longz1, 'string') );    %Longitud en Z en metros
 
%Datos de analisis transitorio
inc = str2double( get(handles.incrementos1, 'string') );      %Numero de incrementos o avances en el tiempo
dt = str2double( get(handles.pasotemporal, 'string') );       %Incremento en el tiempo en segundos              
vel = str2double( get(handles.velocidadtras1, 'string') );    %Velocidad de desplazamiento en milimetros
%%%Apartir de aqui hacia abajo se mencionan los calculos necesarios para
%%%iniciar el codigo, tanto de herramienta como caracteristicas generales
alfa=densidad*Calorespec; %%calculo de alfa
 
%%Calculos necesarios para calcular el tamaño del mallado
dx = Lx/Nx;           %Elemento diferencial en X
dy = Ly/Ny;           %Elemento diferencial en Y
dz = Lz/Nz;           %Elemento diferencial en Z
 
%%calculos necesarios para caraterizar la herramienta
gruponodos=diametroh/dx;    %Nodos que representan la herramienta en X
grupoenteronodos=round(gruponodos); %Numero entero de nodos para represntar la herramienta en X
gruponodosy=diametroh/dy;    %Nodos que representan la herramienta en Y
grupoenteronodosy=round(gruponodosy); %Numero entero de nodos para represntar la herramienta en Y
grupoenteronodos1=round(grupoenteronodos/2); %Usado para establecer la posicion desde donde se llena el conjunto de nodos de la herramienta.
profundidadnodos=profundidadh/dz;   %Nodos que representan la penetracion
profunidadnodosentero=round(profundidadnodos);  %Numero entero de nodos que representan la profunidad
distanciar=(dt*inc)*vel;%Calcula la distancia recorrida con esa velocidad y ese tiempo
 
%%Calculo para los coeficientes usados en el calculo de las temperaturas
rx=ku*dt/(dx^2*alfa);              %Coeficiente de incremento en x
ry=ku*dt/(dy^2*alfa);              %Coeficiente de incremento en y
rz=ku*dt/(dy^2*alfa);              %Coeficiente de incremento en z
px=ku/dx;                          %Coeficiente usado para la frontera superior en X
py=ku/dy;                          %Coeficiente usado para la frontera superior en Y    
pz=ku/dz;                          %Coeficiente usado para la frontera superior en Z
limite=rx+ry+rz;                   %Coeficiente limite del termino central
 
%%Inicizalicion de las matrices para el calculo de temperaturas
N=Nx*Ny*Nz;             %El numero de incognitas de la matriz
A = zeros(N,N);           %Matriz de coeficientes
T=zeros(N,1);           %Matriz de temperaturas(grafica)
sigma=zeros(N,inc);     %Matriz para almacenar los resultados de esfuerzos
deformacionplas=zeros(N,1);  %Matriz de deformacion plastica
Lfinal=zeros(N,1);      %Matriz de velocidades finales(grafica)
B=zeros(N,inc);         %Matriz de Resultados(grafica)
NFP=((-ku/dx)-h);       %Avance en las fronteras hacia atras nodo primario
NFPA=((-ku/dx)-h);      %Avance en las fronteras hacia atras nodo primario
NFS=(ku/dx);            %Avance en las fronteras hacia atras nodo secundario
NFSA=(ku/dx);           %Avance en las fronteras hacia atras nodo secundario
 
%%Primera alerta del programa para evitar que la herramienta abandoned la
%%placa de material
warndlg('El tiempo de simulacion usado para esa velocidad es muy grande y la herramienta abandonara la placa. Reducelo','uipanel1');
 
 
resultado = Ly + Lx;
set (handles.resultado,'String',resultado);
 
 
function profundidad1_Callback(hObject, eventdata, handles)
str2double( get(handles.profunidad1, 'string') );              %Diametro de la herramienta en milimetros
% hObject    handle to profundidad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of profundidad1 as text
%        str2double(get(hObject,'String')) returns contents of profundidad1 as a double
 
 
% --- Executes during object creation, after setting all properties.
function profundidad1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to profundidad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
 
 
 
function resultado_Callback(hObject, eventdata, handles)
% hObject    handle to resultado (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of resultado as text
%        str2double(get(hObject,'String')) returns contents of resultado as a double
 
 
% --- Executes during object creation, after setting all properties.
function resultado_CreateFcn(hObject, eventdata, handles)
% hObject    handle to resultado (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
 
 
Este es el codigo fuente
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
%Datos termicos
Tamb=300;            %Temperatura en grados Kelvin
h=20;               %Coeficiente de conveccion: Watt/metro*Kelvin
ku=196;             %Conductividad termica:Watt/metro*Kelvin
q=0;                %Generacion de calor: Watt/metro^3
densidad=2800;      %kilogramo/metro^3
Calorespec=880;     %Calor especifico J/Kg*Kelvin
alfa=densidad*Calorespec;
omega=0.0000245;     %Coeficiente de expansion termica /°C
moduloYoung=73100000000;    %Modulo de eslasticidad aluminio
%Datos de nodos y longitudes
Nx=50;              %Numero de nodos en X
Nz=10;              %Numero de nodos en Y
Ny=50;              %Numero de nodos en Z
Lx=.07;              %Longitud en X en metros
Ly=.07;              %Longitud en Y en metros
Lz=.0063;         %Longitud en Z en metros
dx=Lx/Nx;           %Elemento diferencial en X
dy=Ly/Ny;           %Elemento diferencial en Y
dz=Lz/Nz;           %Elemento diferencial en Z
%Datos de analisis transitorio
inc=40000;               %Numero de incrementos o avances en el tiempo
dt=0.0005;               %Incremento en el tiempo en segundos              
vel=.0025;                %Velocidad de desplazamiento en milimetros
distanciar=(dt*inc)*vel;%Calcula la distancia recorrida con esa velocidad y ese tiempo
%Descrpcion de herramienta
diametroh=.015;              %Diametro de la herramienta en milimetros
gruponodos=diametroh/dx;    %Nodos que representan la herramienta en X
grupoenteronodos=round(gruponodos); %Numero entero de nodos para represntar la herramienta en X
gruponodosy=diametroh/dy;    %Nodos que representan la herramienta en Y
grupoenteronodosy=round(gruponodosy); %Numero entero de nodos para represntar la herramienta en Y
grupoenteronodos1=round(grupoenteronodos/2); %Usado para establecer la posicion desde donde se llena el conjunto de nodos de la herramienta.
profundidadh=.0005;                 %Profundidad de penetracion
profundidadnodos=profundidadh/dz;   %Nodos que representan la penetracion
profunidadnodosentero=round(profundidadnodos);  %Numero entero de nodos que representan la profunidad
%Coeficientes de nodos internos
rx=ku*dt/(dx^2*alfa);              %Coeficiente de incremento en x
ry=ku*dt/(dy^2*alfa);              %Coeficiente de incremento en y
rz=ku*dt/(dy^2*alfa);              %Coeficiente de incremento en z
px=ku/dx;                          %Coeficiente usado para la frontera superior en X
py=ku/dy;                          %Coeficiente usado para la frontera superior en Y    
pz=ku/dz;                          %Coeficiente usado para la frontera superior en Z
limite=rx+ry+rz;                   %Coeficiente limite del termino central
%Inicializacion de las matrices
N=Nx*Ny*Nz;             %El numero de incognitas de la matriz
A=zeros(N,N);           %Matriz de coeficientes
T=zeros(N,1);           %Matriz de temperaturas(grafica)
sigma=zeros(N,inc);     %Matriz para almacenar los resultados de esfuerzos
deformacionplas=zeros(N,1);  %Matriz de deformacion plastica
Lfinal=zeros(N,1);      %Matriz de velocidades finales(grafica)
B=zeros(N,inc);         %Matriz de Resultados(grafica)
NFP=((-ku/dx)-h);       %Avance en las fronteras hacia atras nodo primario
NFPA=((-ku/dx)-h);      %Avance en las fronteras hacia atras nodo primario
NFS=(ku/dx);            %Avance en las fronteras hacia atras nodo secundario
NFSA=(ku/dx);           %Avance en las fronteras hacia atras nodo secundario
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Condicion para detener el programa en caso que la velocidad y el tiempo de
%simulacion provoquen que la herramienta abandone la placa%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if distanciar>Lx-diametroh;  %Condicion para evitar que la herramienta salga de la placa
f = warndlg('El tiempo de simulacion usado para esa velocidad es muy grande y la herramienta abandonara la placa. Reducelo','Warning');
break;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Condicion para detener el programa en caso que el incremento de tiempo
%usado sobrepase el limite impuesto para evitar divergencias%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if limite>=.5           %Condicion para evitar divergencias en la solucion
f = warndlg('El paso temporal es demasiado grande y creara divergencias en la solucion','Warning');
break;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%DESDE ESTE PUNTO HACIA ABAJO COMIENZA EL ALGORITMO DE SOLUCION PARA EL
%SISTEMA EN ESTADO TRANSITORIO Y PUNTO DE CALOR MOVIL%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=1;        %Es el contador que indica cuanto tiempo se tiene que permanecer en cada posicion
m=1;        %Es el contador que provoca el movimiento del grupo de nodos.
e=((N-(Nx*Ny)*profunidadnodosentero)+Ny/2)-grupoenteronodos1;
for f=1:inc-1;          %Ciclo para el analisis transitorio  
%Inicializacion de ciclos para nodos internos
for k=2:Nz-1;               %Controla el nivel en Z
    for i=2:Nx-1;           %Controla la fila de posiciones en X
        for j=2:Ny-1;       %Controla las columnas en Y
            n=j+(i-1)*Ny+((k-1)*Nx*Ny);   %Le da un numero al nodo en vez de una coordenada
            A(n,n)=-2*(rx+ry+rz);   %Nodo central
            A(n,n-1)=1*ry;     %Nodo en bloque anterior X
            A(n,n+1)=1*ry;     %Nodo en bloque siguiente X
            A(n,n+Ny)=1*rx;    %Nodo en bloque siguiente Y
            A(n,n-Ny)=1*rx;    %Nodo en bloque anterior Y
            A(n,n-Nx*Ny)=1*rz; %Nodo en bloque anterior en Z
            A(n,n+Nx*Ny)=1*rz; %Nodo en bloque siguiente en Z
        end
    end
end
for u=1:N;      %Ciclo para colocar las temperaturas inciales
    B(u,1)=300;   %Temperatura en el tiempo N
end
%%%Solucion frontera a conveccion cara inferior%%%
k=1;                           %La posicion en Z no cambia en esa cara.
for i=2:Nx-1;                  %Controla la distancia en Z.                 
        for j=2:Ny-1;          %La posicion en X necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFSA*B(n+Nx*Ny,f))/NFPA;    %Frontera en cara inferior
        end
end
%%%Solucion frontera a conveccion cara frontal%%%
i=1;                           %La posicion en Y no cambia en esa cara.
for k=1:Nz-1;                  %Controla la distancia en Z.                 
        for j=1:Ny;            %Controla la distancia en X.
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %La posicion en X necesita esta cambiando
        B(n,f+1)=(-h*Tamb-NFS*B(n+Nx,f))/NFP;    %Frontera en cara frontal
        end
end
%%%Solucion borde izquierdo cara superior a conveccion%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
j=Ny;
for i=1:Nx;                %Controla la distancia en Z.                 
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-Nx*Ny,f))/NFP;  %Frontera en cara superior
end
%%%Solucion borde frontal cara superior a conveccion%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
i=1;
for j=1:Ny;                %Controla la distancia en Z.                 
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-Nx*Ny,f))/NFP;  %Frontera en cara superior
end
%%%Solucion borde trasero cara superior a conveccion%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
i=Nx;
for j=1:Ny;                %Controla la distancia en Z.                 
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-Nx*Ny,f))/NFP;  %Frontera en cara superior
end
 
%%%Solucion frontera a conveccion cara superior%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
for i=2:Nx-1;                %Controla la distancia en Z.                 
        for j=2:Ny-1;        %La posicion en X necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        aumento=(dx/vel);   %El tiempo que se debe permanecer en cada nodo
        if aumento>=dt;     %Condicion: Si el tiempo de permanencia (aumento) es mayor al paso temporal se cumple
            estancia=dt*b;  %Variable que ira actualizando conforme se avanza en el tiempo
            if estancia>=aumento;   %Condicion: Si el tiempo de estancia es mayor igual al de permanencia.
                m=m+1;              %Contador que provoca el movimiento del grupo de nodos
                b=1;                %Reset del contador para la permanencia de los nodos.
            end
        end
for cont3=1:profunidadnodosentero;      %Contador para el acomodo de los nodos en direccion Z      
    for cont1=1:grupoenteronodos;       %Contador para el acomodo de los nodos en direccion X
        for cont2=1:grupoenteronodosy;   %Contador para el acomodo de los nodos en direccion Y
        u=cont2+(cont1-1)*Ny+((cont3-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(e+u+((Ny)*(m-1)),f)=705;              %Le da el valor temperatura al grupo de nodos moviles
        end
    end
end
        B(n,f+1)=(-h*Tamb-px*(B(n+Ny,f)+B(n-Ny,f))-py*(B(n-1,f)+B(n+1,f))-pz*B(n-Nx*Ny,f))/(-(2*px+2*py+pz-h));  %Frontera modificada para la cara superior para lograr una mejor captacion del calor
        end
end
b=b+1; %Actualizacion del contador para el tiempo que se debe permanecer en cada nodo
%%%Solucion frontera a conveccion cara trasera%%%
i=Nx;                      %La posicion en X no cambia en esa cara.
for k=1:Nz-1;              %Controla la distancia en Z.                 
        for j=1:Ny;        %La posicion en Y necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFSA*B(n-Ny,f))/NFPA;   %Frontera en cara trasera
        end
end
%%%Solucion frontera a conveccion cara izquierda%%%
j=Ny;                        %La posicion en X no cambia en esa cara.
for i=1:Nx-1;                %Controla la distancia en Z.                 
        for k=1:Nz-1;        %La posicion en Y necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-1,f))/NFP;    %Frontera en cara izquierda
        end
end
%%%Solucion frontera a conveccion cara derecha%%%
j=1;                         %La posicion en X no cambia en esa cara.
for i=2:Nx-1;                %Controla la distancia en Z.                 
        for k=1:Nz;          %La posicion en Y necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFSA*B(n+1,f))/NFPA;    %Frontera en cara derecha
        end
end
%%%Solucion para nodos interiores
for i=2:Nx-1;               %Controla el nivel de posiciones en Z
    for k=2:Nz-1;           %Controla la fila de posiciones de los coeficientes
        for j=2:Ny-1;       %Controla las columnas de los coeficientes
            n=j+(i-1)*Ny+((k-1)*Nx*Ny);  %Le da un numero al nodo en vez de una coordenada
            B(n,f+1)=((A(n,n)*B(n,f)+(A(n,n-1)*B(n-1,f)+A(n,n+1)*B(n+1,f)+A(n,n+Ny)*B(n+Ny,f)+A(n,n-Ny)*B(n-Ny,f)+A(n,n-Nx*Ny)*B(n-Nx*Ny,f)+A(n,n+Nx*Ny)*B(n+Nx*Ny,f))+(q*dt/alfa))+B(n,f));
        end
    end
end
end
for f=1:N;      %Ciclo para imprimir el ultimo paso temporal
    T(f,1)=B(f,inc);    %El ultimo paso temporal se almacena en un vector columna para imprimirlo
end
for i=1:inc;    %Ciclo para intercambiar de incremento de tiempo
    for f=1:N;  %Ciclo para intercambiar de posicion en renglon
        sigma(f,i)=moduloYoung*omega*(B(f,i)-Tamb); %Matriz de esfuerzos           
    end
end
M = max(sigma,[],2);    %Define los valores maximos de cada renglon
for f=1:N;      %Ciclo para imprimir las longitudes finales de la deformacion
    Lfinal(f,1)=((((M(f,1)/moduloYoung)+1)*dx));%Operacion para imprimir las longitudes finales
end
%Obtencion del grafico de temperatura en funcion de las distancias
f1=figure;      %Imprime una figura del grafico en funcion de las distancias nodales
reshape(T,Nx,Ny,Nz);        %Acomoda el vector unidad en una matriz tridimensional
[x,y,z]= meshgrid(dx:dx:Lx,dy:dy:Ly,dz:dz:Lz);      %Crea un mallado con esas especificaciones
slice(x,y,z,ans(:,:,:),[dx,Lx],[dy,Ly],[dz,Lz]);    %Crea el grafico en 3D
pause(.125);
shading interp              %El color amarillo es el mayor y el azul el menor
xlabel('X','fontSize',12);  %Coloca la etiqueta en X
ylabel('Y','fontSize',12);  %Coloca la etiqueta en Y
zlabel('Z','fontSize',12);  %Coloca la etiqueta en Z
colorbar('location','eastoutside','fontsize',12);   %Ubicacion de la barra de color
c= colorbar;    %Comando para imprimir la barra de colores
c.Label.String = 'Temperatura °K';  %Etiqueta de la barra de color
title('Difusión de Calor','fontsize',12);   %Titulo del grafico
grid on;    %El mallado es visible
axis('equal');  %Todos los ejes tengan la misma proporcion
ax.XAxisLocation = 'origin';    %Colocar el origen de los ejes
 
%Obtencion del grafico de temperatura en funcion de los nodos
f2=figure;          %Imprime una figura del grafico en funcion de las distancias nodales
reshape(T,Nx,Ny,Nz);        %Acomoda el vector unidad en una matriz tridimensional
[x,y,z]= meshgrid(1:1:Nx,1:1:Ny,1:1:Nz);        %Crea un mallado con esas especificaciones
slice(x,y,z,ans(:,:,:),[1,Nx],[1,Ny],[1,Nz]);   %Crea el grafico en 3D
shading interp              %El color amarillo es el mayor y el azul el menor
xlabel('X','fontSize',12);  %Coloca la etiqueta en X
ylabel('Y','fontSize',12);  %Coloca la etiqueta en Y
zlabel('Z','fontSize',12);  %Coloca la etiqueta en Z
colorbar('location','eastoutside','fontsize',12);   %Ubicacion de la barra de color
c= colorbar;    %Comando para imprimir la barra de colores
c.Label.String = 'Temperatura °C';  %Etiqueta de la barra de color
title('Difusión de Calor','fontsize',12);   %Titulo del grafico
grid on;    %El mallado es visible
axis('equal');  %Todos los ejes tengan la misma proporcion
ax.XAxisLocation = 'origin';    %Colocar el origen de los ejes
 
%Obtencion del grafico en funcion de las deformaciones
f3=figure;          %Imprime una figura del grafico en funcion de los esfuerzos maximos
reshape(M,Nx,Ny,Nz);        %Acomoda el vector unidad en una matriz tridimensional
[x,y,z]= meshgrid(1:1:Nx,1:1:Ny,1:1:Nz);        %Crea un mallado con esas especificaciones
slice(x,y,z,ans(:,:,:),[1,Nx],[1,Ny],[1,Nz]);   %Crea el grafico en 3D
shading interp              %El color amarillo es el mayor y el azul el menor
xlabel('X','fontSize',12);  %Coloca la etiqueta en X
ylabel('Y','fontSize',12);  %Coloca la etiqueta en Y
zlabel('Z','fontSize',12);  %Coloca la etiqueta en Z
colorbar('location','eastoutside','fontsize',12);   %Ubicacion de la barra de color
c= colorbar;    %Comando para imprimir la barra de colores
c.Label.String = 'Esfuerzo Pa';  %Etiqueta de la barra de color
title('Esfuerzos Termicos','fontsize',12);   %Titulo del grafico
grid on;    %El mallado es visible
axis('equal');  %Todos los ejes tengan la misma proporcion
ax.XAxisLocation = 'origin';    %Colocar el origen de los ejes
 
%Obtencion del grafico de las deformaciones en funcion de los nodos
f4=figure;      %Imprime una figura del grafico en funcion de las distancias nodales
reshape(M,Nx,Ny,Nz);        %Acomoda el vector unidad en una matriz tridimensional
[x,y,z]= meshgrid(dx:dx:Lx,dy:dy:Ly,dz:dz:Lz);      %Crea un mallado con esas especificaciones
slice(x,y,z,ans(:,:,:),[dx,Lx],[dy,Ly],[dz,Lz]);    %Crea el grafico en 3D
pause(.125);
shading interp              %El color amarillo es el mayor y el azul el menor
xlabel('X','fontSize',12);  %Coloca la etiqueta en X
ylabel('Y','fontSize',12);  %Coloca la etiqueta en Y
zlabel('Z','fontSize',12);  %Coloca la etiqueta en Z
colorbar('location','eastoutside','fontsize',12);   %Ubicacion de la barra de color
c= colorbar;    %Comando para imprimir la barra de colores
c.Label.String = 'Esfuerzos Pa';  %Etiqueta de la barra de color
title('Esfuerzos Termicos','fontsize',12);   %Titulo del grafico
grid on;    %El mallado es visible
axis('equal');  %Todos los ejes tengan la misma proporcion
ax.XAxisLocation = 'origin';    %Colocar el origen de los ejes



123
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 26
Ha aumentado su posición en 2 puestos en Matlab (en relación al último mes)
Gráfica de Matlab

Ayuda en GUI novato

Publicado por Luis (16 intervenciones) el 10/09/2019 00:21:20
Ese es el codigo m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
function varargout = deformacion3ejecutable(varargin)
% DEFORMACION3EJECUTABLE MATLAB code for deformacion3ejecutable.fig
%      DEFORMACION3EJECUTABLE, by itself, creates a new DEFORMACION3EJECUTABLE or raises the existing
%      singleton*.
%
%      H = DEFORMACION3EJECUTABLE returns the handle to a new DEFORMACION3EJECUTABLE or the handle to
%      the existing singleton*.
%
%      DEFORMACION3EJECUTABLE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DEFORMACION3EJECUTABLE.M with the given input arguments.
%
%      DEFORMACION3EJECUTABLE('Property','Value',...) creates a new DEFORMACION3EJECUTABLE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before deformacion3ejecutable_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to deformacion3ejecutable_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help deformacion3ejecutable

% Last Modified by GUIDE v2.5 05-Sep-2019 22:00:46

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @deformacion3ejecutable_OpeningFcn, ...
                   'gui_OutputFcn',  @deformacion3ejecutable_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before deformacion3ejecutable is made visible.
function deformacion3ejecutable_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to deformacion3ejecutable (see VARARGIN)

% Choose default command line output for deformacion3ejecutable
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes deformacion3ejecutable wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = deformacion3ejecutable_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Conductividad1_Callback(hObject, eventdata, handles)
str2double( get(handles.Conductividad1, 'string') );   %Conductividad termica
% hObject    handle to Conductividad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Conductividad1 as text
%        str2double(get(hObject,'String')) returns contents of Conductividad1 as a double


% --- Executes during object creation, after setting all properties.
function Conductividad1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Conductividad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function densidad1_Callback(hObject, eventdata, handles)
% hObject    handle to densidad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of densidad1 as text
%        str2double(get(hObject,'String')) returns contents of densidad1 as a double
densidad = str2double( get(handles.densidad1, 'string') );      %kilogramo/metro^3

% --- Executes during object creation, after setting all properties.
function densidad1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to densidad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function Calosrespe1_Callback(hObject, eventdata, handles)
% hObject    handle to Calosrespe1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Calosrespe1 as text
%        str2double(get(hObject,'String')) returns contents of Calosrespe1 as a double
Calorespec = str2double( get(handles.Calosrespe1, 'string') );     %Calor especifico

% --- Executes during object creation, after setting all properties.
function Calosrespe1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Calosrespe1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Coeficientedila1_Callback(hObject, eventdata, handles)
str2double( get(handles.Coeficientedila1, 'string') );     %Coeficiente de expansion termica /°C
% hObject    handle to Coeficientedila1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Coeficientedila1 as text
%        str2double(get(hObject,'String')) returns contents of Coeficientedila1 as a double


% --- Executes during object creation, after setting all properties.
function Coeficientedila1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Coeficientedila1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Moduloyoung1_Callback(hObject, eventdata, handles)
str2double( get(handles.Moduloyoung1, 'string') );    %Modulo de eslasticidad aluminio
% hObject    handle to Moduloyoung1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Moduloyoung1 as text
%        str2double(get(hObject,'String')) returns contents of Moduloyoung1 as a double


% --- Executes during object creation, after setting all properties.
function Moduloyoung1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Moduloyoung1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Temperaturamb1_Callback(hObject, eventdata, handles)
str2double( get(handles.Temperaturamb1, 'string') );    %Temperatura en grados
% hObject    handle to Temperaturamb1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Temperaturamb1 as text
%        str2double(get(hObject,'String')) returns contents of Temperaturamb1 as a double


% --- Executes during object creation, after setting all properties.
function Temperaturamb1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Temperaturamb1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function conveccion1_Callback(hObject, eventdata, handles)
str2double( get(handles.conveccion1, 'string') );   %Coeficiente de conveccion
% hObject    handle to conveccion1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of conveccion1 as text
%        str2double(get(hObject,'String')) returns contents of conveccion1 as a double


% --- Executes during object creation, after setting all properties.
function conveccion1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to conveccion1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function longx1_Callback(hObject, eventdata, handles)
str2double( get(handles.longx1, 'string') );    %Longitud en X en metros
% hObject    handle to longx1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of longx1 as text
%        str2double(get(hObject,'String')) returns contents of longx1 as a double


% --- Executes during object creation, after setting all properties.
function longx1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to longx1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function longz1_Callback(hObject, eventdata, handles)
str2double( get(handles.longz1, 'string') );    %Longitud en Z en metros
% hObject    handle to longz1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of longz1 as text
%        str2double(get(hObject,'String')) returns contents of longz1 as a double


% --- Executes during object creation, after setting all properties.
function longz1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to longz1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function longy1_Callback(hObject, eventdata, handles)
str2double( get(handles.longy1, 'string') );    %Longitud en Y en metros
% hObject    handle to longy1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of longy1 as text
%        str2double(get(hObject,'String')) returns contents of longy1 as a double


% --- Executes during object creation, after setting all properties.
function longy1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to longy1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function nodosx1_Callback(hObject, eventdata, handles)
str2double( get(handles.nodosx1, 'string') );    %Numero de nodos en X
% hObject    handle to nodosx1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of nodosx1 as text
%        str2double(get(hObject,'String')) returns contents of nodosx1 as a double


% --- Executes during object creation, after setting all properties.
function nodosx1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nodosx1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function nodosz1_Callback(hObject, eventdata, handles)
str2double( get(handles.nodosz1, 'string') );    %Numero de nodos en Y
% hObject    handle to nodosz1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of nodosz1 as text
%        str2double(get(hObject,'String')) returns contents of nodosz1 as a double


% --- Executes during object creation, after setting all properties.
function nodosz1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nodosz1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function nodosy1_Callback(hObject, eventdata, handles)
str2double( get(handles.nodosy1, 'string') );    %Numero de nodos en Z
% hObject    handle to nodosy1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of nodosy1 as text
%        str2double(get(hObject,'String')) returns contents of nodosy1 as a double


% --- Executes during object creation, after setting all properties.
function nodosy1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nodosy1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function pasotemporal_Callback(hObject, eventdata, handles)
% hObject    handle to pasotemporal (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of pasotemporal as text
%        str2double(get(hObject,'String')) returns contents of pasotemporal as a double


% --- Executes during object creation, after setting all properties.
function pasotemporal_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pasotemporal (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function velocidadtras1_Callback(hObject, eventdata, handles)
str2double( get(handles.velocidadtras1, 'string') );
% hObject    handle to velocidadtras1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of velocidadtras1 as text
%        str2double(get(hObject,'String')) returns contents of velocidadtras1 as a double


% --- Executes during object creation, after setting all properties.
function velocidadtras1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to velocidadtras1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function incrementos1_Callback(hObject, eventdata, handles)
str2double( get(handles.incrementos1, 'string') );
% hObject    handle to incrementos1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of incrementos1 as text
%        str2double(get(hObject,'String')) returns contents of incrementos1 as a double


% --- Executes during object creation, after setting all properties.
function incrementos1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to incrementos1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function diametro1_Callback(hObject, eventdata, handles)
str2double( get(handles.diametro1, 'string') );   %Diametro de la herramienta en milimetros
% hObject    handle to diametro1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of diametro1 as text
%        str2double(get(hObject,'String')) returns contents of diametro1 as a double


% --- Executes during object creation, after setting all properties.
function diametro1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to diametro1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function temperatura1_Callback(hObject, eventdata, handles)
str2double( get(handles.temperatura1, 'string') );              %Diametro de la herramienta en milimetros
% hObject    handle to temperatura1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of temperatura1 as text
%        str2double(get(hObject,'String')) returns contents of temperatura1 as a double


% --- Executes during object creation, after setting all properties.
function temperatura1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to temperatura1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in calcular.
function calcular_Callback(hObject, eventdata, handles)
% hObject    handle to calcular (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% propiedades del ambiente
Tamb = str2double( get(handles.Temperaturamb1, 'string') );    %Temperatura en grados
h = str2double( get(handles.conveccion1, 'string') );   %Coeficiente de conveccion

% propiedades del material
ku = str2double( get(handles.Conductividad1, 'string') );   %Conductividad termica
densidad = str2double( get(handles.densidad1, 'string') );      %kilogramo/metro^3
Calorespec = str2double( get(handles.Calosrespe1, 'string') );     %Calor especifico
omega = str2double( get(handles.Coeficientedila1, 'string') );     %Coeficiente de expansion termica /°C
moduloYoung = str2double( get(handles.Moduloyoung1, 'string') );    %Modulo de eslasticidad aluminio

% propiedades de la herramienta
diametroh = str2double( get(handles.diametro1, 'string') );              %Diametro de la herramienta en milimetros
Therr = str2double( get(handles.temperatura1, 'string') );
profundidadh = str2double( get(handles.profundidad1, 'string') );                 %Profundidad de penetracion

%Datos de nodos y longitudes
Nx = str2double( get(handles.nodosx1, 'string') );    %Numero de nodos en X
Nz = str2double( get(handles.nodosz1, 'string') );    %Numero de nodos en Y
Ny = str2double( get(handles.nodosy1, 'string') );    %Numero de nodos en Z
Lx = str2double( get(handles.longx1, 'string') );    %Longitud en X en metros
Ly = str2double( get(handles.longy1, 'string') );    %Longitud en Y en metros
Lz = str2double( get(handles.longz1, 'string') );    %Longitud en Z en metros

%Datos de analisis transitorio
inc = str2double( get(handles.incrementos1, 'string') );      %Numero de incrementos o avances en el tiempo
dt = str2double( get(handles.pasotemporal, 'string') );       %Incremento en el tiempo en segundos
vel = str2double( get(handles.velocidadtras1, 'string') );    %Velocidad de desplazamiento en milimetros
%%%Apartir de aqui hacia abajo se mencionan los calculos necesarios para
%%%iniciar el codigo, tanto de herramienta como caracteristicas generales
alfa=densidad*Calorespec; %%calculo de alfa

%%Calculos necesarios para calcular el tamaño del mallado
dx = Lx/Nx;           %Elemento diferencial en X
dy = Ly/Ny;           %Elemento diferencial en Y
dz = Lz/Nz;           %Elemento diferencial en Z

%%calculos necesarios para caraterizar la herramienta
gruponodos=diametroh/dx;    %Nodos que representan la herramienta en X
grupoenteronodos=round(gruponodos); %Numero entero de nodos para represntar la herramienta en X
gruponodosy=diametroh/dy;    %Nodos que representan la herramienta en Y
grupoenteronodosy=round(gruponodosy); %Numero entero de nodos para represntar la herramienta en Y
grupoenteronodos1=round(grupoenteronodos/2); %Usado para establecer la posicion desde donde se llena el conjunto de nodos de la herramienta.
profundidadnodos=profundidadh/dz;   %Nodos que representan la penetracion
profunidadnodosentero=round(profundidadnodos);  %Numero entero de nodos que representan la profunidad
distanciar=(dt*inc)*vel;%Calcula la distancia recorrida con esa velocidad y ese tiempo

%%Calculo para los coeficientes usados en el calculo de las temperaturas
rx=ku*dt/(dx^2*alfa);              %Coeficiente de incremento en x
ry=ku*dt/(dy^2*alfa);              %Coeficiente de incremento en y
rz=ku*dt/(dy^2*alfa);              %Coeficiente de incremento en z
px=ku/dx;                          %Coeficiente usado para la frontera superior en X
py=ku/dy;                          %Coeficiente usado para la frontera superior en Y    
pz=ku/dz;                          %Coeficiente usado para la frontera superior en Z
limite=rx+ry+rz;                   %Coeficiente limite del termino central

%%Inicizalicion de las matrices para el calculo de temperaturas
N=10;             %El numero de incognitas de la matriz
inc=5;
A = zeros(N,N);           %Matriz de coeficientes
T=zeros(N,1);           %Matriz de temperaturas(grafica)
sigma=zeros(N,inc);     %Matriz para almacenar los resultados de esfuerzos
deformacionplas=zeros(N,1);  %Matriz de deformacion plastica
Lfinal=zeros(N,1);      %Matriz de velocidades finales(grafica)
B=zeros(N,inc);         %Matriz de Resultados(grafica)
NFP=((-ku/dx)-h);       %Avance en las fronteras hacia atras nodo primario
NFPA=((-ku/dx)-h);      %Avance en las fronteras hacia atras nodo primario
NFS=(ku/dx);            %Avance en las fronteras hacia atras nodo secundario
NFSA=(ku/dx);           %Avance en las fronteras hacia atras nodo secundario

%%Primera alerta del programa para evitar que la herramienta abandoned la
%%placa de material
if Lx>Ly
warndlg('El tiempo de simulacion usado para esa velocidad es muy grande y la herramienta abandonara la placa. Reducelo','uipanel1');
end



%%%En el espacio dejado arriba sera para colocar los respectivos warning
%%%pero estos seran colocados la final, por lo qque apartir de se colocara
%%%la parte medular del codigo numerico
b=1;        %Es el contador que indica cuanto tiempo se tiene que permanecer en cada posicion
m=1;        %Es el contador que provoca el movimiento del grupo de nodos.
e=((N-(Nx*Ny)*profunidadnodosentero)+Ny/2)-grupoenteronodos1;
for f=1:inc-1;          %Ciclo para el analisis transitorio  
%Inicializacion de ciclos para nodos internos
for k=2:Nz-1;               %Controla el nivel en Z
    for i=2:Nx-1;           %Controla la fila de posiciones en X
        for j=2:Ny-1;       %Controla las columnas en Y
            n=j+(i-1)*Ny+((k-1)*Nx*Ny);   %Le da un numero al nodo en vez de una coordenada
            A(n,n)=-2*(rx+ry+rz);   %Nodo central
            A(n,n-1)=1*ry;     %Nodo en bloque anterior X
            A(n,n+1)=1*ry;     %Nodo en bloque siguiente X
            A(n,n+Ny)=1*rx;    %Nodo en bloque siguiente Y
            A(n,n-Ny)=1*rx;    %Nodo en bloque anterior Y
            A(n,n-Nx*Ny)=1*rz; %Nodo en bloque anterior en Z
            A(n,n+Nx*Ny)=1*rz; %Nodo en bloque siguiente en Z
        end
    end
    resultado = Ly + Lx;%%%enunciado de prueba%%%
    set (handles.resultado,'String',resultado);%%%enunciado de prueba%%%
end
for u=1:N;      %Ciclo para colocar las temperaturas inciales
    B(u,1)=300;   %Temperatura en el tiempo N
end
%%%Solucion frontera a conveccion cara inferior%%%
k=1;                           %La posicion en Z no cambia en esa cara.
for i=2:Nx-1;                  %Controla la distancia en Z.                 
        for j=2:Ny-1;          %La posicion en X necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFSA*B(n+Nx*Ny,f))/NFPA;    %Frontera en cara inferior
        end
end
%%%Solucion frontera a conveccion cara frontal%%%
i=1;                           %La posicion en Y no cambia en esa cara.
for k=1:Nz-1;                  %Controla la distancia en Z.                 
        for j=1:Ny;            %Controla la distancia en X.
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %La posicion en X necesita esta cambiando
        B(n,f+1)=(-h*Tamb-NFS*B(n+Nx,f))/NFP;    %Frontera en cara frontal
        end
end
%%%Solucion borde izquierdo cara superior a conveccion%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
j=Ny;
for i=1:Nx;                %Controla la distancia en Z.                 
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-Nx*Ny,f))/NFP;  %Frontera en cara superior
end
%%%Solucion borde frontal cara superior a conveccion%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
i=1;
for j=1:Ny;                %Controla la distancia en Z.                 
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-Nx*Ny,f))/NFP;  %Frontera en cara superior
end
%%%Solucion borde trasero cara superior a conveccion%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
i=Nx;
for j=1:Ny;                %Controla la distancia en Z.                 
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-Nx*Ny,f))/NFP;  %Frontera en cara superior
end

%%%Solucion frontera a conveccion cara superior%%%
k=Nz;                      %La posicion en Z no cambia en esa cara.
for i=2:Nx-1;                %Controla la distancia en Z.                 
        for j=2:Ny-1;        %La posicion en X necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        aumento=(dx/vel);   %El tiempo que se debe permanecer en cada nodo
        if aumento>=dt;     %Condicion: Si el tiempo de permanencia (aumento) es mayor al paso temporal se cumple
            estancia=dt*b;  %Variable que ira actualizando conforme se avanza en el tiempo
            if estancia>=aumento;   %Condicion: Si el tiempo de estancia es mayor igual al de permanencia.
                m=m+1;              %Contador que provoca el movimiento del grupo de nodos
                b=1;                %Reset del contador para la permanencia de los nodos.
            end
        end
for cont3=1:profunidadnodosentero;      %Contador para el acomodo de los nodos en direccion Z      
    for cont1=1:grupoenteronodos;       %Contador para el acomodo de los nodos en direccion X
        for cont2=1:grupoenteronodosy;   %Contador para el acomodo de los nodos en direccion Y
        u=cont2+(cont1-1)*Ny+((cont3-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(e+u+((Ny)*(m-1)),f)=Therr;              %Le da el valor temperatura al grupo de nodos moviles
        end
    end
end
        B(n,f+1)=(-h*Tamb-px*(B(n+Ny,f)+B(n-Ny,f))-py*(B(n-1,f)+B(n+1,f))-pz*B(n-Nx*Ny,f))/(-(2*px+2*py+pz-h));  %Frontera modificada para la cara superior para lograr una mejor captacion del calor
        end
end
b=b+1; %Actualizacion del contador para el tiempo que se debe permanecer en cada nodo
%%%Solucion frontera a conveccion cara trasera%%%
i=Nx;                      %La posicion en X no cambia en esa cara.
for k=1:Nz-1;              %Controla la distancia en Z.                 
        for j=1:Ny;        %La posicion en Y necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFSA*B(n-Ny,f))/NFPA;   %Frontera en cara trasera
        end
end
%%%Solucion frontera a conveccion cara izquierda%%%
j=Ny;                        %La posicion en X no cambia en esa cara.
for i=1:Nx-1;                %Controla la distancia en Z.                 
        for k=1:Nz-1;        %La posicion en Y necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFS*B(n-1,f))/NFP;    %Frontera en cara izquierda
        end
end
%%%Solucion frontera a conveccion cara derecha%%%
j=1;                         %La posicion en X no cambia en esa cara.
for i=2:Nx-1;                %Controla la distancia en Z.                 
        for k=1:Nz;          %La posicion en Y necesita esta cambiando
        n=j+(i-1)*Ny+((k-1)*Nx*Ny);     %Le da un numero al nodo en vez de una coordenada
        B(n,f+1)=(-h*Tamb-NFSA*B(n+1,f))/NFPA;    %Frontera en cara derecha
        end
end
%%%Solucion para nodos interiores
for i=2:Nx-1;               %Controla el nivel de posiciones en Z
    for k=2:Nz-1;           %Controla la fila de posiciones de los coeficientes
        for j=2:Ny-1;       %Controla las columnas de los coeficientes
            n=j+(i-1)*Ny+((k-1)*Nx*Ny);  %Le da un numero al nodo en vez de una coordenada
            B(n,f+1)=((A(n,n)*B(n,f)+(A(n,n-1)*B(n-1,f)+A(n,n+1)*B(n+1,f)+A(n,n+Ny)*B(n+Ny,f)+A(n,n-Ny)*B(n-Ny,f)+A(n,n-Nx*Ny)*B(n-Nx*Ny,f)+A(n,n+Nx*Ny)*B(n+Nx*Ny,f))+(q*dt/alfa))+B(n,f));
        end
    end
end
end
for f=1:N;      %Ciclo para imprimir el ultimo paso temporal
    T(f,1)=B(f,inc);    %El ultimo paso temporal se almacena en un vector columna para imprimirlo
end
for i=1:inc;    %Ciclo para intercambiar de incremento de tiempo
    for f=1:N;  %Ciclo para intercambiar de posicion en renglon
        sigma(f,i)=moduloYoung*omega*(B(f,i)-Tamb); %Matriz de esfuerzos           
    end
end
M = max(sigma,[],2);    %Define los valores maximos de cada renglon
for f=1:N;      %Ciclo para imprimir las longitudes finales de la deformacion
    Lfinal(f,1)=((((M(f,1)/moduloYoung)+1)*dx));%Operacion para imprimir las longitudes finales
end
%%%%Hasta esta parte se contiene la parte de resolucion del algoritmo. De
%%%%aqui hacia abajo se menciona el algoritmo para la graficacion de datos

%Obtencion del grafico de temperatura en funcion de las distancias
f1=figure;      %Imprime una figura del grafico en funcion de las distancias nodales
reshape(T,Nx,Ny,Nz);        %Acomoda el vector unidad en una matriz tridimensional
[x,y,z]= meshgrid(dx:dx:Lx,dy:dy:Ly,dz:dz:Lz);      %Crea un mallado con esas especificaciones
slice(x,y,z,ans(:,:,:),[dx,Lx],[dy,Ly],[dz,Lz]);    %Crea el grafico en 3D
pause(.125);
shading interp              %El color amarillo es el mayor y el azul el menor
xlabel('X','fontSize',12);  %Coloca la etiqueta en X
ylabel('Y','fontSize',12);  %Coloca la etiqueta en Y
zlabel('Z','fontSize',12);  %Coloca la etiqueta en Z
colorbar('location','eastoutside','fontsize',12);   %Ubicacion de la barra de color
c= colorbar;    %Comando para imprimir la barra de colores
c.Label.String = 'Temperatura °K';  %Etiqueta de la barra de color
title('Difusión de Calor','fontsize',12);   %Titulo del grafico
grid on;    %El mallado es visible
axis('equal');  %Todos los ejes tengan la misma proporcion
ax.XAxisLocation = 'origin';    %Colocar el origen de los ejes

%Obtencion del grafico en funcion de las deformaciones
f3=figure;          %Imprime una figura del grafico en funcion de los esfuerzos maximos
reshape(M,Nx,Ny,Nz);        %Acomoda el vector unidad en una matriz tridimensional
[x,y,z]= meshgrid(1:1:Nx,1:1:Ny,1:1:Nz);        %Crea un mallado con esas especificaciones
slice(x,y,z,ans(:,:,:),[1,Nx],[1,Ny],[1,Nz]);   %Crea el grafico en 3D
shading interp              %El color amarillo es el mayor y el azul el menor
xlabel('X','fontSize',12);  %Coloca la etiqueta en X
ylabel('Y','fontSize',12);  %Coloca la etiqueta en Y
zlabel('Z','fontSize',12);  %Coloca la etiqueta en Z
colorbar('location','eastoutside','fontsize',12);   %Ubicacion de la barra de color
c= colorbar;    %Comando para imprimir la barra de colores
c.Label.String = 'Esfuerzo Pa';  %Etiqueta de la barra de color
title('Esfuerzos Termicos','fontsize',12);   %Titulo del grafico
grid on;    %El mallado es visible
axis('equal');  %Todos los ejes tengan la misma proporcion
ax.XAxisLocation = 'origin';    %Colocar el origen de los ejes






function profundidad1_Callback(hObject, eventdata, handles)
              %Diametro de la herramienta en milimetros
% hObject    handle to profundidad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of profundidad1 as text
%        str2double(get(hObject,'String')) returns contents of profundidad1 as a double


% --- Executes during object creation, after setting all properties.
function profundidad1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to profundidad1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function resultado_Callback(hObject, eventdata, handles)
% hObject    handle to resultado (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of resultado as text
%        str2double(get(hObject,'String')) returns contents of resultado as a double


% --- Executes during object creation, after setting all properties.
function resultado_CreateFcn(hObject, eventdata, handles)
% hObject    handle to resultado (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


Por alguna razon se queda ciclado en la parte de la matriz A y aun no puedo imprimir ninguna grafica
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar