Gillee

52 Reputation

One Badge

1 years, 318 days

MaplePrimes Activity


These are questions asked by Gillee

Hi, 

I was able to determine a cubic spline fit, F(v), to x1 and y1. Now I have vector x2 which I would like to use F(v) to calculate y2 as another Vector[row]. I am having trouble accomplishing this task. Any help is greatly appreciated. Thanks.
 

restart

 x1 := Vector[row]([0.8e-1, .28, .48, .68, .88, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.2]);

 y1 := Vector[row]([-10.081, -10.054, -10.018, -9.982, -9.939, -9.911, -9.861, -9.8, -9.734, -9.659, -9.601, -9.509, -9.4, -9.293, -9.183, -9.057, -8.931, -8.806, -8.676, -8.542, -8.405, -8.265]);

 

m := ArrayTools[Dimensions](x1);

maxx := rhs(m[1]);

 

F := proc (v) options operator, arrow; CurveFitting:-Spline(x1, y1, v, degree = 3) end proc;

 

x2 := Vector[row]([seq(log10(2*10^x1[k]), k = 1 .. maxx)])

 

y2:=?

 

Pts1 := plot(x1, y1, style = point, symbol = diamond, gridlines = true, color = red);

plt_sp := plot(F(v), v = x1[1] .. x1[maxx], color = blue);

plots:-display(Pts1, plt_sp)``

"# How to calculate Vector y2 using spline fit F with x2"? "    x1:=Vector[row]([0.08,0.28,0.48,0.68,0.88,1,1.2,1.4,1.6,1.8,2,2.2,2.4,2.6,2.8,3,3.2,3.4,3.6,3.8,4,4.2]):    y1:=Vector[row]([-10.081,-10.054,-10.018,-9.982,-9.939,-9.911,-9.861,-9.8,-9.734,-9.659,-9.601,-9.509,-9.4,-9.293,-9.183,-9.057,-8.931,-8.806,-8.676,-8.542,-8.405,-8.265]):    m:=ArrayTools[Dimensions](x1):  maxx:=rhs(m[1]):      F:=v->CurveFitting:-Spline(x1,y1, v,degree=3):    x2:=Vector[row]([seq(log10(2*10^(x1[k])),k=1..maxx)]):                   #` PLOT RESULTS`   Pts1:=plot(x1,y1,style=point,symbol = diamond, gridlines=true, color = red):       plt_sp:=plot(F(v),v=x1[1]..x1[maxx],color = blue):     plots:-display(Pts1,plt_sp);     "

 

``

``


 

Download splfit.mw

Hi,

I am trying to curve fit data using NLPSolve. I noticed that the evaluation time for NLPSolve seems really long. Did I mess up in using NLPSolve? 

 

Thanks you for any suggests or comments.
 

restart; kernelopts(version); interface(version); multithread_capability := kernelopts(multithreaded); Number_of_CPUs := kernelopts(numcpus)
NULL

8

(1)

``

``

"#` How` can I decrease the evaluation time of NLPSolve or are there better methods"?"" ""

``

SoS:=proc(E0::float,E00::float,alpha::float,beta:: float)::float;

NULL

NULL

Experimental Data

 

Erealm := Vector[row]([1235.773, 1383.61, 1457.262, 1500.264, 1550.184, 1612.161, 512.7612, 656.6554, 743.6461, 793.375, 855.7937, 939.1199, 79.9523, 128.1375, 167.1459, 193.592, 230.5401, 287.8348, 22.389, 29.41424, 35.91883, 40.86366, 48.79128, 63.4475, 15.34275, 17.10101, 18.63288, 19.77424, 21.5671, 24.84739, 13.8321, 14.52843, 15.07626, 15.47014, 16.07713, 17.16574, 13.13383, 13.63704, 13.95888, 14.16849, 14.46123, 14.93971, 12.76736, 13.2203, 13.50072, 13.673, 13.89852, 14.23242]); LFm := Vector[row]([.156795, .1248161, .1108722, .1032334, 0.9474591e-1, 0.8496174e-1, .361361, .3020133, .2706018, .2546556, .2356126, .2121333, .6883826, .6532309, .6155578, .5906291, .5578895, .5123917, .394458, .5326358, .6095816, .6489291, .6894866, .7232845, .1456468, .2226473, .2826954, .3228541, .3789496, .4632182, 0.6758032e-1, 0.9437384e-1, .1198126, .1387971, .1680719, .2181531, 0.5173809e-1, 0.586771e-1, 0.6591736e-1, 0.7206892e-1, 0.8243504e-1, .1024519, 0.457877e-1, 0.493836e-1, 0.5191291e-1, 0.539114e-1, 0.5708074e-1, 0.6330242e-1])

NULL``

Enter Initial Guesses for HN equation

 

ind0 := min[index](Erealm); ind00 := max[index](Erealm); indLF := max[index](LFm); E0_g := Erealm(ind0); E00_g := 3*Erealm(ind00); `α_g` := 2.0*LFm(indLF)/Pi; `β_g` := `α_g`/(10.0); m := ArrayTools[Dimensions](LFm); maxx := rhs(m[1]); Ecomplex := Vector[row]([seq(Complex(Erealm[k], Erealm[k]*LFm[k]), k = 1 .. maxx)]); `ωτ` := Vector[row]([seq(abs((((E0_g-E00_g)/(Ecomplex[k]-E00_g))^(1/`β_g`)-1)^(1/`α_g`)/(I)), k = 1 .. maxx)]); Erealc := Vector[row]([seq(Re(E00_g+(E0_g-E00_g)/(1+(I*`ωτ`[k])^`α_g`)^`β_g`), k = 1 .. maxx)]); Eimagc := Vector[row]([seq(Im(E00_g+(E0_g-E00_g)/(1+(I*`ωτ`[k])^`α_g`)^`β_g`), k = 1 .. maxx)]); LFc := Vector[row]([seq(Eimagc[k]/Erealc[k], k = 1 .. maxx)]); pltm := plots:-loglogplot(Erealm, LFm, style = point, symbol = solidcircle, gridlines = true, color = red); pltc := plots:-loglogplot(Erealc, LFc, style = point, symbol = diamond, gridlines = true, color = blue); plots:-display(pltm, pltc, title = "Wicket Plot from Guesses       measured - red    calculated - blue"); Sum_of_Squares := SoS(E0_g, E00_g, `α_g`, `β_g`)

.2049941769

(2.1)

``

NULL

NULL

NULL

Run Optimizer

 

lol := .7; hil := 1.3; le0 := lol*E0_g; he0 := hil*E0_g; le00 := lol*E00_g; he00 := hil*E00_g; al := lol*`α_g`; ah := hil*`α_g`; bl := lol*`β_g`; bh := hil*`β_g`; parameterRange := le0 .. he0, le00 .. he00, al .. ah, bl .. bh; soln := Optimization:-NLPSolve(SoS, parameterRange); HN := soln[2]; E0_s := HN[1]; E00_s := HN[2]; `α_s` := HN[3]; `β_s` := HN[4]; `ωτ_s` := Vector[row]([seq(abs((((E0_s-E00_s)/(Ecomplex[k]-E00_s))^(1/`β_s`)-1)^(1/`α_s`)/(I)), k = 1 .. maxx)]); Erealc_s := Vector[row]([seq(Re(E00_s+(E0_s-E00_s)/(1+(I*`ωτ_s`[k])^`α_s`)^`β_s`), k = 1 .. maxx)]); Eimagc_s := Vector[row]([seq(Im(E00_s+(E0_s-E00_s)/(1+(I*`ωτ_s`[k])^`α_s`)^`β_s`), k = 1 .. maxx)]); LFc_s := Vector[row]([seq(Eimagc_s[k]/Erealc_s[k], k = 1 .. maxx)])

[0.648163470800135894e-2, Vector[column](%id = 18446747242105787086)]

(3.1)

NULL

NULL

NULL

Plot Wicket Plot with Optimized HN Parameters

 

pltm_s := plots:-loglogplot(Erealm, LFm, style = point, symbol = solidcircle, gridlines = true, color = red); pltc_s := plots:-loglogplot(Erealc_s, LFc_s, style = point, symbol = diamond, gridlines = true, color = blue); plots:-display(pltm_s, pltc_s, title = "Wicket Plot after Optimization  (measured - red    calculated - blue)"); E0_soln := E0_s; E00_soln := E00_s; `α_soln` := `α_s`; `β_soln` := `β_s`; Sum_of_Squares := soln[1]

0.648163470800135894e-2

(4.1)

NULL


 

Download HN_fit_of_DMA_data_ss_proc_v5a.mw

I am learning how to use Threads. I looked for an example code in Start / Programming / Example: Task Model and Multithreaded Programming. I found a MandelBrot code, which I was able to change a value in the If -then statement to run in Threads or no Threads mode. I added a time() function to get a sense of the execution time. The results are about 140s with Threads and 91s with no Threads. I would have thought that the execution time would be smaller in the Threads mode than in the no Threads mode. Did I assume incorrectly that I was creating a Threads and no Threads situations by modifying the if-then statement? Or is this not good example? Here is the code:

Threads_Ex3a.mw

I was trying to answer a question by torabi 25, August 14, 2017 to speed up his calculations. I got this idea of converting the original code to a procedure - that was not easy, run the procedure and obtain a value of time() to establish a baseline, and making sure the answer from the procedure was the same as from torabi 25. So far so good. Then I would compile the procedure, execute it, and get another value for time(). Hopefully the compiled procedure will be faster than the uncompiled procedure. I am close, but - please see if you can fix my compiler error. Thanks!


 

restart

pa := proc (k::integer, h::float, N::float, nu::float, E_m::float, E_c::float, rho_m::float, rho_c::float, d::(Matrix()))::float; local lambda_m::float, lambda_c::float, mu_m::float, mu_c::float, Z::float, U::float, S::float, e2::float, f::float, W::float, z::float, b::integer, alpha::integer, beta::integer; lambda_m := nu*E_m/((1+nu)*(1-2*nu)); lambda_c := nu*E_c/((1+nu)*(1-2*nu)); mu_m := E_m/(2+2*nu); mu_c := E_c/(2+2*nu); Z := rho_m+(rho_c-rho_m)*(1/2+z/h)^N; U := lambda_m+(lambda_c-lambda_m)*(1/2+z/h)^N; S := mu_m+(mu_c-mu_m)*(1/2+z/h)^N; e2 := 0.; for alpha from 0 to k-2 do for b from 0 to k-2 do for beta from 0 to k-1 do f := 2*S*d[beta+1, alpha+1]*W(beta)*sqrt(alpha+1/2)*orthopoly:-P(alpha, z)*d[2, b+1]*sqrt(b+1/2)*orthopoly:-P(b, z); e2 := e2-(int(f, z = -(1/2)*h .. (1/2)*h)) end do end do end do end proc

NULL

k := 6; h := 1.; N := .5; nu := .3; E_m := 7.0*10^10; E_c := 3.80*10^11; rho_m := 2702.; rho_c := 3800.; d := Matrix([evalf([0, 0, 0, 0, 0, 0, 0, 0]), evalf([sqrt(3), 0, 0, 0, 0, 0, 0, 0]), evalf([0, sqrt(15), 0, 0, 0, 0, 0, 0]), evalf([sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0]), evalf([0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0]), evalf([sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0]), evalf([0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0]), evalf([sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0])], datatype = float[8])

time(pa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d))

2.156

(1)

pa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

-0.3192307695e12*W(1)+0.4396880666e12*W(3)-0.1474586302e12*W(5)-0.9235575679e11*W(2)+0.1979090107e12*W(4)

(2)

# Original Answer:        -3.192307692*10^11*W(1)+4.396880662*10^11*W(3)-1.474586301*10^11*W(5)-9.235575669*10^10*W(2)+1.979090105*10^11*W(4);NULL

cpa := Compiler:-Compile(pa)

Error, (in Compiler:-Compile) Array parameter types must specify a hardware datatype

 

time(cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d))

0.

(3)

cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

NULL


 

Download for_(5).mw

 


``

How can I convert the result (2) to equal to the trigonometric identity (kw/s^2)*tanh(a*s/2)?

``

g := kw*piecewise(t < a, t, t < 2*a, 2*a-t)

kw*piecewise(t < a, t, t < 2*a, 2*a-t)

(1)

simplify((int(exp(-s*t)*g, t = 0 .. a)+int(exp(-s*t)*g, t = a .. 2*a))/(1-exp(-2*a*s)))

-(exp(-a*s)-1)*kw/((exp(-a*s)+1)*s^2)

(2)

``


Download trigonometric_id.mw

 
Page 1 of 1