Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.maple > #1148 > unrolled thread
| Started by | "Thomas D. Dean" <tomdean@speakeasy.org> |
|---|---|
| First post | 2015-06-25 09:29 -0700 |
| Last post | 2015-07-07 09:54 -0700 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.soft-sys.math.maple
Local Variables in Proc "Thomas D. Dean" <tomdean@speakeasy.org> - 2015-06-25 09:29 -0700
Re: Local Variables in Proc Joe Riel <joer@san.rr.com> - 2015-07-03 13:04 -0700
Re: Local Variables in Proc "Thomas D. Dean" <tomdean@speakeasy.org> - 2015-07-07 02:58 -0700
Re: Local Variables in Proc Joe Riel <joer@san.rr.com> - 2015-07-07 09:54 -0700
| From | "Thomas D. Dean" <tomdean@speakeasy.org> |
|---|---|
| Date | 2015-06-25 09:29 -0700 |
| Subject | Local Variables in Proc |
| Message-ID | <KaidndA_z5XxsRHInZ2dnUU7-LmdnZ2d@megapath.net> |
See below.
I want to make a group of variables in a proc local.
But, I call Syrup[Solve] and the variables are not resolved.
How do I do this?
Tom Dean
## simulate the source for the ideal loop,
## http://www.vlf.it/feletti2/idealloop.html
##
## restart;
with(Syrup): with(ScientificConstants):
loop := proc(wire_sel)
description "Calculations on a loop antenna designed for VLF applications."
" The argument wire_sel is the index into the wire constants vectors."
" The return value, vout, contains a variable f, the frequency."
" ";
local A, R, gauge, Dia, len_kg, dia, N, L, Cl;
local Cs, Rin, Cin, Rlk, mu, Z, Clight, lambda, h;
local rho, B, omega, Vsource, ckt, volts, others, vout;
local resist;
# loop dimensions
A :=(475/10*Unit('cm'))^2;
R :=60;
gauge := < 26, 24, 22, 20, 18>;
Dia := < 410, 510, 640, 800, 1000>;
len_kg := <8875, 5485, 3464, 2167, 1366> / 10;
resist := 348/10*len_kg/1000; ## ohms/km * m / (m/km)
##wire_sel := 4;
dia := Dia[wire_sel]*Unit('um');
N := floor(simplify(len_kg[wire_sel]*Unit('m') / 4 / sqrt(A)));
L := 80*Unit('mH');
Cl :='Cl'; ## prevent errors
Cl := 235*Unit('pF');
Cs :='Cs'; ## prevent errors
Cs := 510*Unit('pF');
Rin := 75/10*Unit('kOmega'); ## ad797 differential input stage
Cin := 20*Unit('pF'); ## ad797 differential input stage
Rlk := 100*Unit('MOmega'); ## ad797 differential input stage
##
## derived values from physical constants
mu[0] := GetValue(Constant('mu[0]'))*GetUnit(Constant('mu[0]'));
mu[r] := 1;
Z[0] := GetValue(Constant('Z[0]'))*GetUnit(Constant('Z[0]'));
Clight := GetValue(Constant('c'))*GetUnit(Constant('c'));
lambda := Clight/(f*Unit('Hz'));
h[e] := simplify(2*Pi*N*A*mu[r]/lambda);
rho := 17240*10^(-12)*Unit('Omega*m');
## radiation resistance
R[rad] := simplify(Z[0] * 2/3 * Pi * (h[e]/lambda)^2);
## AC resistance
R[ac] := simplify(4 * N * sqrt(A) / (Pi * dia) *
sqrt(Pi*mu[0]*f*Unit('Hz')
*rho));
## dc resistance
R[dc] := resist[wire_sel]; ##
simplify(4*N*sqrt(A)/((Pi*dia^2)/4)*rho);
## source controlled source
## Z[0] :=GetValue(Constant('Z[0]'));
## mu[0]:=GetValue(Constant('mu[0]'));
## B is in tesla (or Wb, H is A/m, B = mu[0] * mu[r] * H
## use 1pT as source field strength
## B:=convert(1,'units','pT','kg/(A*s^2)');
## H:=solve(B=mu[0]*GetUnit(Constant('mu[0]'))*mu[r]*'H','H');
## H:=1e-12*Unit('T')/mu[0]/GetUnit(Constant('mu[0]'));
##
## Volts = meter^2 * kg / (s^3 * A)
## to get from tesla to volts: simplify(Unit('Hz')*Unit('m^2')*Unit('pT'));
B :=1*Unit('pT');
## or, freq * area * tesla
omega :=2*Pi*f*Unit('Hz');
## loop voltage source
Vsource := simplify(omega*A*N*B);
ckt := "* Ideal Loop Source\n"
"Vloop 1 2 map(convert,Vsource,unit_free)\n"
"Lloop 2 3 map(convert,L,unit_free)\n"
"Rac 3 4 map(convert,R[ac],unit_free)\n"
"Rdc 4 5 map(convert,R[dc],unit_free)\n"
"Rrad 5 6 map(convert,R[rad],unit_free)\n"
"Cloop 6 1 map(convert,Cl,unit_free)\n"
"Cshield1 1 0 map(convert,Cs/2,unit_free)\n"
"Cshield2 6 0 map(convert,Cs/2,unit_free)\n"
"Rload 6 1 map(convert,Rin,unit_free)\n"
"Cload 6 1 map(convert,Cin,unit_free)\n"
"Rleak 1 0 map(convert,Rlk,unit_free)\n"
".end";
#
volts,others:=Solve(ckt,returnall);
assign(volts);
vout:=eval(v[6]-v[1],s=I*map(convert,omega,unit_free));
vout:=simplify(vout);
print(Rlk);
evala(vout);
end proc:
vout := loop(4):
[toc] | [next] | [standalone]
| From | Joe Riel <joer@san.rr.com> |
|---|---|
| Date | 2015-07-03 13:04 -0700 |
| Message-ID | <876161c8if.fsf@san.rr.com> |
| In reply to | #1148 |
"Thomas D. Dean" <tomdean@speakeasy.org> writes:
> See below.
>
> I want to make a group of variables in a proc local.
>
> But, I call Syrup[Solve] and the variables are not resolved.
>
> How do I do this?
>
> Tom Dean
>
> ## simulate the source for the ideal loop,
> ## http://www.vlf.it/feletti2/idealloop.html
> ##
> ## restart;
> with(Syrup): with(ScientificConstants):
> loop := proc(wire_sel)
> description "Calculations on a loop antenna designed for VLF applications."
> " The argument wire_sel is the index into the wire constants vectors."
> " The return value, vout, contains a variable f, the frequency."
> " ";
> local A, R, gauge, Dia, len_kg, dia, N, L, Cl;
> local Cs, Rin, Cin, Rlk, mu, Z, Clight, lambda, h;
> local rho, B, omega, Vsource, ckt, volts, others, vout;
> local resist;
> # loop dimensions
> A :=(475/10*Unit('cm'))^2;
> R :=60;
> gauge := < 26, 24, 22, 20, 18>;
> Dia := < 410, 510, 640, 800, 1000>;
> len_kg := <8875, 5485, 3464, 2167, 1366> / 10;
> resist := 348/10*len_kg/1000; ## ohms/km * m / (m/km)
> ##wire_sel := 4;
> dia := Dia[wire_sel]*Unit('um');
> N := floor(simplify(len_kg[wire_sel]*Unit('m') / 4 / sqrt(A)));
> L := 80*Unit('mH');
> Cl :='Cl'; ## prevent errors
> Cl := 235*Unit('pF');
> Cs :='Cs'; ## prevent errors
> Cs := 510*Unit('pF');
> Rin := 75/10*Unit('kOmega'); ## ad797 differential input stage
> Cin := 20*Unit('pF'); ## ad797 differential input stage
> Rlk := 100*Unit('MOmega'); ## ad797 differential input stage
> ##
> ## derived values from physical constants
> mu[0] := GetValue(Constant('mu[0]'))*GetUnit(Constant('mu[0]'));
> mu[r] := 1;
> Z[0] := GetValue(Constant('Z[0]'))*GetUnit(Constant('Z[0]'));
> Clight := GetValue(Constant('c'))*GetUnit(Constant('c'));
> lambda := Clight/(f*Unit('Hz'));
> h[e] := simplify(2*Pi*N*A*mu[r]/lambda);
> rho := 17240*10^(-12)*Unit('Omega*m');
> ## radiation resistance
> R[rad] := simplify(Z[0] * 2/3 * Pi * (h[e]/lambda)^2);
> ## AC resistance
> R[ac] := simplify(4 * N * sqrt(A) / (Pi * dia) *
> sqrt(Pi*mu[0]*f*Unit('Hz')
> *rho));
> ## dc resistance
> R[dc] := resist[wire_sel]; ##
> simplify(4*N*sqrt(A)/((Pi*dia^2)/4)*rho);
> ## source controlled source
> ## Z[0] :=GetValue(Constant('Z[0]'));
> ## mu[0]:=GetValue(Constant('mu[0]'));
> ## B is in tesla (or Wb, H is A/m, B = mu[0] * mu[r] * H
> ## use 1pT as source field strength
> ## B:=convert(1,'units','pT','kg/(A*s^2)');
> ## H:=solve(B=mu[0]*GetUnit(Constant('mu[0]'))*mu[r]*'H','H');
> ## H:=1e-12*Unit('T')/mu[0]/GetUnit(Constant('mu[0]'));
> ##
> ## Volts = meter^2 * kg / (s^3 * A)
> ## to get from tesla to volts: simplify(Unit('Hz')*Unit('m^2')*Unit('pT'));
> B :=1*Unit('pT');
> ## or, freq * area * tesla
> omega :=2*Pi*f*Unit('Hz');
>
> ## loop voltage source
> Vsource := simplify(omega*A*N*B);
>
> ckt := "* Ideal Loop Source\n"
> "Vloop 1 2 map(convert,Vsource,unit_free)\n"
> "Lloop 2 3 map(convert,L,unit_free)\n"
> "Rac 3 4 map(convert,R[ac],unit_free)\n"
> "Rdc 4 5 map(convert,R[dc],unit_free)\n"
> "Rrad 5 6 map(convert,R[rad],unit_free)\n"
> "Cloop 6 1 map(convert,Cl,unit_free)\n"
> "Cshield1 1 0 map(convert,Cs/2,unit_free)\n"
> "Cshield2 6 0 map(convert,Cs/2,unit_free)\n"
> "Rload 6 1 map(convert,Rin,unit_free)\n"
> "Cload 6 1 map(convert,Cin,unit_free)\n"
> "Rleak 1 0 map(convert,Rlk,unit_free)\n"
> ".end";
> #
> volts,others:=Solve(ckt,returnall);
> assign(volts);
> vout:=eval(v[6]-v[1],s=I*map(convert,omega,unit_free));
> vout:=simplify(vout);
> print(Rlk);
> evala(vout);
> end proc:
>
> vout := loop(4):
What problem are you seeing? The procedure runs here, but
I'm using a developmental version of Syrup. It returns
100 [MΩ]
--
Joe Riel
[toc] | [prev] | [next] | [standalone]
| From | "Thomas D. Dean" <tomdean@speakeasy.org> |
|---|---|
| Date | 2015-07-07 02:58 -0700 |
| Message-ID | <TO-dnWPKi9gtPwbInZ2dnUU7-b-dnZ2d@megapath.net> |
| In reply to | #1151 |
On 07/03/15 13:04, Joe Riel wrote: > "Thomas D. Dean" <tomdean@speakeasy.org> writes: > > <snip> > > What problem are you seeing? The procedure runs here, but > I'm using a developmental version of Syrup. It returns > > 100 [MΩ] > I did not see my follow-up. If the variables at the top of the loop proc are local, I believe Solve does not see them. > lprint(vout); Rin*Vsource*(1+2*I*Pi*f*Cs*Rlk)/(-Rin-R[ac]-R[dc]-R[rad]+4*Rin*Rlk*Pi^2*f^2*Cs *Cin*R[dc]+4*Rin*Rlk*Pi^2*f^2*Cs*Cin*R[rad]+4*Rin*Rlk*Pi^2*f^2*Cs*Cin*R[ac]+4* Rin*Rlk*Pi^2*f^2*Cs*Cl*R[dc]+4*Rin*Rlk*Pi^2*f^2*Cs*Cl*R[rad]+4*Rin*Rlk*Pi^2*f^ 2*Cs*Cl*R[ac]+Pi^2*f^2*Cs^2*Rlk*Rin*R[dc]+Pi^2*f^2*Cs^2*Rlk*Rin*R[rad]+Pi^2*f^ 2*Cs^2*Rlk*Rin*R[ac]+4*Pi^2*f^2*Cs*Rlk*L+2*Pi^2*f^2*Cs*Rin*L+4*Rin*Pi^2*f^2* Cin*L+4*Rin*Pi^2*f^2*Cl*L-2*I*Pi*f*L-I*Pi*f*Cs*Rin*R[dc]-I*Pi*f*Cs*Rin*R[ac]-2 *I*Pi*f*Cs*Rlk*R[dc]-2*I*Pi*f*Cs*Rlk*R[ac]-2*I*Rin*Pi*f*Cl*R[dc]-2*I*Pi*f*Cs* Rlk*Rin-2*I*Rin*Pi*f*Cin*R[dc]-2*I*Rin*Pi*f*Cin*R[ac]-2*I*Rin*Pi*f*Cl*R[ac]-2* I*Pi*f*Cin*R[rad]*Rin-2*I*Pi*f*Cl*R[rad]*Rin-I*Pi*f*Cs*R[rad]*Rin-2*I*Pi*f*Cs* R[rad]*Rlk+2*I*Pi^3*f^3*Cs^2*Rlk*Rin*L+8*I*Rin*Rlk*Pi^3*f^3*Cs*Cin*L+8*I*Rin* Rlk*Pi^3*f^3*Cs*Cl*L) If the variables at the top of the loop proc are global, they are resolved in the output. > lprint(vout); 207910026653364218531593147959/100*431^(1/2)*Pi*f*(1+102000*I*Pi*f)/( 1472043695300510799566465673155530920000000000*f^(5/2)*Pi^2-\ 275807751189202459178030605427833680000000*I*f^(3/2)*Pi-\ 2515346568072981843848888330395200000*f^(1/2)-\ 8579230077542378853734926131788585600000000*I*431^(1/2)*Pi*f+ 504585722070646176901051491206400000000000000000*I*431^(1/2)*Pi^3*f^3+ 23876801514746295125740205994438446400000000000*431^(1/2)*Pi^2*f^2-\ 81053810280021791299895549227584000000*431^(1/2)+82597277124675000*431^(1/2)* Pi^6*f^6-15475742554950*I*431^(1/2)*Pi^5*f^5-141137643*431^(1/2)*Pi^4*f^4) Tom Dean
[toc] | [prev] | [next] | [standalone]
| From | Joe Riel <joer@san.rr.com> |
|---|---|
| Date | 2015-07-07 09:54 -0700 |
| Message-ID | <87oajnlxgv.fsf@san.rr.com> |
| In reply to | #1152 |
"Thomas D. Dean" <tomdean@speakeasy.org> writes:
> On 07/03/15 13:04, Joe Riel wrote:
>> "Thomas D. Dean" <tomdean@speakeasy.org> writes:
>>
>>
> <snip>
>>
>> What problem are you seeing? The procedure runs here, but
>> I'm using a developmental version of Syrup. It returns
>>
>> 100 [MΩ]
>>
>
> I did not see my follow-up.
I believe that was because it was an email to my home account.
That's fine, but I'll reply here for now.
>
> If the variables at the top of the loop proc are local, I believe
> Solve does not see them.
>
>> lprint(vout);
> Rin*Vsource*(1+2*I*Pi*f*Cs*Rlk)/(-Rin-R[ac]-R[dc]-R[rad]+4*Rin*Rlk*Pi^2*f^2*Cs
> *Cin*R[dc]+4*Rin*Rlk*Pi^2*f^2*Cs*Cin*R[rad]+4*Rin*Rlk*Pi^2*f^2*Cs*Cin*R[ac]+4*
> Rin*Rlk*Pi^2*f^2*Cs*Cl*R[dc]+4*Rin*Rlk*Pi^2*f^2*Cs*Cl*R[rad]+4*Rin*Rlk*Pi^2*f^
> 2*Cs*Cl*R[ac]+Pi^2*f^2*Cs^2*Rlk*Rin*R[dc]+Pi^2*f^2*Cs^2*Rlk*Rin*R[rad]+Pi^2*f^
> 2*Cs^2*Rlk*Rin*R[ac]+4*Pi^2*f^2*Cs*Rlk*L+2*Pi^2*f^2*Cs*Rin*L+4*Rin*Pi^2*f^2*
> Cin*L+4*Rin*Pi^2*f^2*Cl*L-2*I*Pi*f*L-I*Pi*f*Cs*Rin*R[dc]-I*Pi*f*Cs*Rin*R[ac]-2
> *I*Pi*f*Cs*Rlk*R[dc]-2*I*Pi*f*Cs*Rlk*R[ac]-2*I*Rin*Pi*f*Cl*R[dc]-2*I*Pi*f*Cs*
> Rlk*Rin-2*I*Rin*Pi*f*Cin*R[dc]-2*I*Rin*Pi*f*Cin*R[ac]-2*I*Rin*Pi*f*Cl*R[ac]-2*
> I*Pi*f*Cin*R[rad]*Rin-2*I*Pi*f*Cl*R[rad]*Rin-I*Pi*f*Cs*R[rad]*Rin-2*I*Pi*f*Cs*
> R[rad]*Rlk+2*I*Pi^3*f^3*Cs^2*Rlk*Rin*L+8*I*Rin*Rlk*Pi^3*f^3*Cs*Cin*L+8*I*Rin*
> Rlk*Pi^3*f^3*Cs*Cl*L)
>
>
> If the variables at the top of the loop proc are global, they are
> resolved in the output.
>
>> lprint(vout);
> 207910026653364218531593147959/100*431^(1/2)*Pi*f*(1+102000*I*Pi*f)/(
> 1472043695300510799566465673155530920000000000*f^(5/2)*Pi^2-\
> 275807751189202459178030605427833680000000*I*f^(3/2)*Pi-\
> 2515346568072981843848888330395200000*f^(1/2)-\
> 8579230077542378853734926131788585600000000*I*431^(1/2)*Pi*f+
> 504585722070646176901051491206400000000000000000*I*431^(1/2)*Pi^3*f^3+
> 23876801514746295125740205994438446400000000000*431^(1/2)*Pi^2*f^2-\
> 81053810280021791299895549227584000000*431^(1/2)+82597277124675000*431^(1/2)*
> Pi^6*f^6-15475742554950*I*431^(1/2)*Pi^5*f^5-141137643*431^(1/2)*Pi^4*f^4)
>
> Tom Dean
That is expected. The string that is the syrup deck is parsed, using
the Maple parse command. Doing so always evaluates symbols in a global
context. If you wanted the local context you would have to embed the
values in the string, say with sprintf or StringTools:-FormatMessage.
For example,
val := x -> map(convert,x,unit_free):
ckt := StringTools:-FormatMessage(
"* Ideal Loop Source\n"
"Vloop 1 2 %1\n"
"Lloop 2 3 %2\n"
...
, val(Vsource)
, val(Lloop)
...);
--
Joe Riel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.maple
csiph-web