problems with mathematica
- To: mathgroup at yoda.physics.unc.edu
- Subject: problems with mathematica
- From: mdiglio%email at yoda.physics.unc.edu (Michael DIGLIO)
- Date: Tue, 15 Dec 92 04:02:47 EST
(* PROBLEMS WITH MATHEMATICA *) (* Computed Temperatures in Pulsed Weldings *) (* PROBLEM: The calculation of temp[x, y, z, t] gets slower and slower ! WHY?? Look at the example at the bottom. *) temp[x_, y_, z_, t_] := ( Up = 32; Ip = 700; Ug = 24; Ig = 175; (* Welding Parameters *) tc = 2; tp = 0.4; v = 3.33; Block[{Ta = 25, etap = 0.95, etag = 0.7, a = 6, ro = 7550, cp = 680, p1 = 0.3, p2 = 0.7}, const = N[2/(cp*ro*(4*3.14159*a*10^-6)^1.5), 4]; (* Physical Constant *) q = (Up*Ip*tp + Ug*Ig*(tc - tp))/(v*10*tc); B = 14.4485 - 27.0392*10^-6*q + 5.5453*10^-9*q^2; ky = Log[20]/((B/2)^2); kx = ((p1/p2)^2)*ky; (* Calculation of the Distribution Coefficients *) toy = N[1/(4*a*ky), 3]; tox = N[1/(4*a*kx), 4]; qp = Round[Up*Ip*etap]; (* Effective Power *) qg = Round[Ug*Ig*etag]; n = Floor[t/tc]; (* Explanation of tempfunc: qp and qg depend on the integration variable d: if n*tc <= d < (n*tc + tp) >> qp; for d = 0 to t. if (n*tc + tp) <= d < n*tc >> qg; for d = 0 to t. *) tempfunc = Ta + const*( qp*NIntegrate[ Exp[- z^2/(4*a*(t - d)) ]/Sqrt[t - d] *( p1*Exp[- ((x - v*d)^2 + y^2)/(4*a*(toy + t - d )) ]/(toy + t - d) + p2*Exp[- ((x - v*d)^2/(4*a*(tox + t - d)) + y^2/(4*a*(toy + t - d))) ]/(Sqrt[(tox + t - d)*(toy + t - d)]) ), {d, 0.001, tp}, AccuracyGoal -> 0, PrecisionGoal -> 4 ] + qg*Sum[ NIntegrate[ Exp[- z^2/(4*a*(t - d)) ]/Sqrt[t - d] *( p1*Exp[- ((x - v*d)^2 + y^2)/(4*a*(toy + t - d )) ]/(toy + t - d) + p2*Exp[- ((x - v*d)^2/(4*a*(tox + t - d)) + y^2/(4*a*(toy + t - d))) ]/(Sqrt[(tox + t - d)*(toy + t - d)]) ), {d, d1*tc + tp, (d1 + 1)*tc}, AccuracyGoal -> 0, PrecisionGoal -> 4 ], {d1, 0, n - 1} ] + qp*Sum[ NIntegrate[ Exp[- z^2/(4*a*(t - d)) ]/Sqrt[t - d] *( p1*Exp[- ((x - v*d)^2 + y^2)/(4*a*(toy + t - d )) ]/(toy + t - d) + p2*Exp[- ((x - v*d)^2/(4*a*(tox + t - d)) + y^2/(4*a*(toy + t - d))) ]/(Sqrt[(tox + t - d)*(toy + t - d)]) ), {d, d1*tc, d1*tc + tp}, AccuracyGoal -> 0, PrecisionGoal -> 4 ], {d1, 1, n - 1} ] + Which[ (t - n*tc) == 0, 0, (t - n*tc) <= tp, qp*NIntegrate[ Exp[- z^2/(4*a*(t - d)) ]/Sqrt[t - d] *( p1*Exp[- ((x - v*d)^2 + y^2)/(4*a*(toy + t - d )) ]/(toy + t - d) + p2*Exp[- ((x - v*d)^2/(4*a*(tox + t - d)) + y^2/(4*a*(toy + t - d))) ]/(Sqrt[(tox + t - d)*(toy + t - d)]) ), {d, n*tc, t - 0.001}, AccuracyGoal -> 0, PrecisionGoal -> 4 ], (t - n*tc) > tp, qp*NIntegrate[ Exp[- z^2/(4*a*(t - d)) ]/Sqrt[t - d] *( p1*Exp[- ((x - v*d)^2 + y^2)/(4*a*(toy + t - d )) ]/(toy + t - d) + p2*Exp[- ((x - v*d)^2/(4*a*(tox + t - d)) + y^2/(4*a*(toy + t - d))) ]/(Sqrt[(tox + t - d)*(toy + t - d)]) ), {d, n*tc, n*tc + tp}, AccuracyGoal -> 0, PrecisionGoal -> 4 ] + qg*NIntegrate[ Exp[- z^2/(4*a*(t - d)) ]/Sqrt[t - d] *( p1*Exp[- ((x - v*d)^2 + y^2)/(4*a*(toy + t - d )) ]/(toy + t - d) + p2*Exp[- ((x - v*d)^2/(4*a*(tox + t - d)) + y^2/(4*a*(toy + t - d))) ]/(Sqrt[(tox + t - d)*(toy + t - d)]) ), {d, n*tc + tp, t - 0.001}, AccuracyGoal -> 0, PrecisionGoal -> 4 ] ] ) ]; Return[tempfunc] ) temptable[x_, y_, z_, t1_, t2_, ti_] := Table[temp[x, y, z, t], {t, t1, t2, ti}] (* EXAMPLE: Timing[temp[120, 0, 5, 36]] {6.43 Second, 1076.07} Timing[temp[120, 0, 5, 36]] {9.39 Second, 1076.07} Timing[temp[120, 0, 5, 36]] {12.52 Second, 1076.07} *) (* If you have any idea to solve the problem, please send an email to: mdiglio at email.tuwien.ac.at Looking forward getting an answer, thanks Frank Peter *)