Message Boards Message Boards

Error in NDSolve of transmission line?

Posted 2 years ago

ClearAll["Global '*"]; NN = 11;

tmax = 6.0;

fN = 1.0;
Rs = 50.0;
Resc_impair = Table[Rc[k] = 0.0, {k, 1, NN, 2}];
Resc_pair = Table[Rc[k] = 0.0, {k, 2, NN, 2}];
Rc[NN] = 1100.0;
Resl_impair = Table[Rl[k] = 0.0, {k, 1, NN, 2}];
Resl_pair = Table[Rl[k] = 0.0, {k, 1, NN, 2}];
Rl[NN] = 200.0;
t0 = 0.0; ts = 1.7 + t0; tflat = 300.0; tfall = 1.7; tc = ts + tflat;
td = tc + tfall; a0 = -10.0*10^3; {ts, tflat, tfall, td - tc}
Vs[t_] := Which[t <= t0, 0, t > t0  && t <= ts, a0 *(t - t0)/ts - t0,
  t > ts && t <= tc, a0, t > t0 && t <= td, a0*((-t + td)/(td - tc)), 
  t > td, 0]
TabVs = Table[{t, Vs[t]/1000}, {t, 0, tmax, 0.01}];
VoltVs = ListPlot[TabVs, PlotRange -> All, 
  PlotStyle -> {AbsoluteThickness[1.4], RGBColor[0, 0, 1], 
    Thickness[0.008]}, FrameLabel -> {"Time(ns)", "Voltage(kV)"}, 
  Joined -> True, GridLines -> {Automatic, Automatic}, 
  FrameTicks -> {Automatic, Automatic}, Frame -> True, 
  LabelStyle -> Directive[Black, 17]]

np = 256; tfourier = 1000;
pulse = Table[Vs[t]/1000, {t, 0, tfourier, 0.05}];
datafin = Table[{f/(1.2), Abs[Fourier[pulse]][[f]]}, {f, 1, 60, 1}];
pVs = ListPlot[datafin, PlotRange -> {{0, 50}, All}, 
  PlotStyle -> {AbsoluteThickness[1.8], RGBColor[0, 1, 0], 
    Thickness[0.008]}, FrameLabel -> {"Frequence(Mhz)", "Voltage(V)"},
   Joined -> True, GridLines -> {Automatic, Automatic}, 
  FrameTicks -> {Automatic, Automatic}, Frame -> True, 
  LabelStyle -> Directive[Black, 17]]
NIntegrate[Vs[t]/1000, {t, 0, 200}]
(*non linear capacitor*)
m = 1.08; V0 = 0.7; Cs0 = 0.000095;
p = (1.0 + 1*V[k][t]/V0)^m
Cv[k_][t_] := which[V[k][t] > -V0, Cs0/p, V[k][t] <= -V0, 10.0]
Cv[k_][t_] := Cs0/p
Ca[Va_] := Cs0/(1.0 + 1*Va/V0)^m 
Cv[NN][t] := 10000000.0;
Plot[{Ca[Va]}, {Va, 0, 15}, AxesLabel -> {"Va", "Ca"}, 
 PlotRange -> {0, Cs0}, PlotStyle -> {Thickness[.01], Red}, 
 TicksStyle -> Directive["Black", 14], 
 AxesStyle -> {{Thick, Black}, {Thick, Black}}, 
 AxesLabel -> {Style["t", Black, Italic, 30], 
   Style["x,Vin", Black, Italic, 30]}, Frame -> False, 
 PlotRange -> All]
(*non linear inductance*)
L0 = 465; La = 4.65; Is = 3.76;
Ls[k_][t_] := (L0 - La)*(Sech[i[k][t]/Is]^2) + La
La1[Ia_] := (L0 - La)*(Sech[(Ia/Is)]^2) + La
Plot[{La1[Ia]}, {Ia, 0, 100}, AxesLabel -> {"Ia", "La1"}, 
 PlotRange -> {0, L0*1.2}, PlotStyle -> {Thickness[.01], Orange}, 
 TicksStyle -> Directive["Black", 14], 
 AxesStyle -> {{Thick, Black}, {Thick, Black}}, 
 AxesLabel -> {Style["t", Black, Italic, 30], 
   Style["x,Vin", Black, Italic, 30]}, Frame -> False, 
 PlotRange -> All]
Ls[NN][t] := 1.0*10^-8
Ls[k_][t_] := 280.0
(*Equation for the First Section*)
eqi = Table[{-i[k]'[t] + 
      Vs[t]/Ls[k][t] - (Rs/Ls[k][t])*
       i[k][t] - (Rc[k]/Ls[k][t] )*(i[k][t] - i[k + 1][t]) - (V[k][
         t])/Ls[k][t] - (Rl[k]/Ls[k][t] )*(i[k][t]) == 
     0, -V[k]'[t] + (i[k][t] - i[k + 1][t])/Cv[k][t] == 0}, {k, 1, 1}];

(*Equation for the intermediate Section*)
eqs = Table[{-i[k]'[
        t] + (Rc[k - 1]/Ls[k][t]) *(i[k - 1][t] - 
         i[k][t]) + (V[k - 1][t])/
       Ls[k][t] - (Rc[k]/Ls[k][t] )*(i[k][t] - i[k + 1][t]) - (V[k][
         t])/Ls[k][t] - (Rl[k]/Ls[k][t] )*(i[k][t]) == 
     0, -V[k]'[t] + (i[k][t] - i[k + 1][t])/Cv[k][t] == 0}, {k, 2, 
    NN - 1}];
eqpartial = Join[eqi, eqs, eqf];
eqfinal = Flatten[eqpartial];
(*Equation for the finale Section*)
eqf = Table[{-i[k]'[
        t] + (Rc[k - 1]/Ls[k][t] )*(i[k - 1][t] - 
         i[k][t]) + (V[k - 1][t])/
       Ls[k][t] - (Rc[k]/Ls[k][t] )*(i[k][t] ) - (V[k][t])/
       Ls[k][t] - (Rl[k]/Ls[k][t] )*(i[k][t]) == 
     0, -V[k]'[t] + (i[k][t])/Cv[k][t] == 0}, {k, NN, NN}];
eqpartial = Join[eqi, eqs, eqf];
eqfinal = Flatten[eqpartial];
initial1 = Flatten[Table[{i[k][0] == 0., V[k][0] == 0.}, {k, 1, NN}]];
Vlist = Flatten[Table[{V[k][t], i[k][t]}, {k, 1, NN}]];
sol = NDSolve[Join[eqfinal, initial1], Vlist, {t, 0., tmax}, 
   MaxSteps -> Infinity];
sol1 = Flatten[sol];
inputiv = 
  Table[{i[k][t] = i[k][t] /. sol1, V[k][t] = V[k][t] /. sol1}, {k, 1,
     NN}];
outiv = Flatten[inputiv];
V[0][t_] := Vs[t] - Rs*i[1][t];
Vfp = Table[
   V[k][t_] = Rc[k]*(i[k][t] - i[k + 1][t]) + V[k][t], {k, 1, NN - 1}];
V[NN][t_] := Rc[NN]*(i[NN][t]) + V[NN][t]
Pload[t_] := V[NN][t] i[NN][t]
Pint[t_] := Vs[t] i[1][t]
VoltFim = 
 ListPlot[outiv, PlotRange -> All, 
  PlotStyle -> {AbsoluteThickness[1.4], RGBColor[0, 0, 1], 
    Thickness[0.008]}, FrameLabel -> {"Time(ns)", "Voltage(kV)"}, 
  Joined -> True, GridLines -> {Automatic, Automatic}, 
  FrameTicks -> {Automatic, Automatic}, Frame -> True, 
  LabelStyle -> Directive[Black, 17]]
Show[VoltVs, VoltFim]
Error:NDSolve::nlnum: The function value {-0.00174035,-1. (1.68378*10^-10-1.66057*10^-17 Rl[2]),0.,0.,0.,0.,0.,0.,0.,0.,<<12>>} is not a list of numbers with dimensions {22} at {t,i[1][t],i[2][t],i[3][t],i[4][t],i[5][t],i[6][t],i[7][t],i[8][t],i[9][t],<<17>>} = {0.0000828415,-1.0813*10^-7,-4.64959*10^-15,0.,0.,0.,0.,0.,0.,0.,<<17>>}.
7 Replies

Hi,

Ah - try this modification:

VoltFim = Plot[outiv, {t, 0, 6},

and eliminate from that expression the option `Joined -> True, then in your final

Show[...]

add the option PlotRange->All

You are plotting both the voltages and currents, even though your y-axis label indicates volts (!) Resulting Show[] plot

`

POSTED BY: Frank Iannarilli

Thanks, Frank.....

Posted 2 years ago

In the WL underscore is interpreted as Blank, so Resl_pair is not a symbol with that name.

Resl_pair // FullForm
(* Pattern[Resl, Blank[pair]] *)

Don't use _ in symbol names.

POSTED BY: Rohit Namjoshi
ClearAll["Global '*"];
NN = 11;

tmax = 6.0;

fN = 1.0;
Rs = 50.0;
Rescimpair = Table[Rc[k] = 0.0, {k, 1, NN, 2}];
Rescpair = Table[Rc[k] = 0.0, {k, 2, NN, 2}];
Rc[NN] = 1100.0;
Reslimpair = Table[Rl[k] = 0.0, {k, 1, NN, 2}];
Reslpair = Table[Rl[k] = 0.0, {k, 2, NN, 2}];
Rl[NN] = 200.0;
t0 = 0.0; ts = 1.7 + t0; tflat = 300.0; tfall = 1.7; tc = ts + tflat;
td = tc + tfall; a0 = -10.0*10^3; {ts, tflat, tfall, td - tc}
Vs[t_] := Which[t <= t0, 0, t > t0  && t <= ts, a0 *(t - t0)/ts - t0,
  t > ts && t <= tc, a0, t > t0 && t <= td, a0*((-t + td)/(td - tc)), 
  t > td, 0]
TabVs = Table[{t, Vs[t]/1000}, {t, 0, tmax, 0.01}];
VoltVs = ListPlot[TabVs, PlotRange -> All, 
  PlotStyle -> {AbsoluteThickness[1.4], RGBColor[0, 0, 1], 
    Thickness[0.008]}, FrameLabel -> {"Time(ns)", "Voltage(kV)"}, 
  Joined -> True, GridLines -> {Automatic, Automatic}, 
  FrameTicks -> {Automatic, Automatic}, Frame -> True, 
  LabelStyle -> Directive[Black, 17]]

np = 256; tfourier = 1000;
pulse = Table[Vs[t]/1000, {t, 0, tfourier, 0.05}];
datafin = Table[{f/(1.2), Abs[Fourier[pulse]][[f]]}, {f, 1, 60, 1}];
pVs = ListPlot[datafin, PlotRange -> {{0, 50}, All}, 
  PlotStyle -> {AbsoluteThickness[1.8], RGBColor[0, 1, 0], 
    Thickness[0.008]}, FrameLabel -> {"Frequence(Mhz)", "Voltage(V)"},
   Joined -> True, GridLines -> {Automatic, Automatic}, 
  FrameTicks -> {Automatic, Automatic}, Frame -> True, 
  LabelStyle -> Directive[Black, 17]]
NIntegrate[Vs[t]/1000, {t, 0, 200}]
(*non linear capacitor*)
m = 1.08; V0 = 0.7; Cs0 = 0.000095;
p = (1.0 + 1*V[k][t]/V0)^m
Cv[k_][t_] := which[V[k][t] > -V0, Cs0/p, V[k][t] <= -V0, 10.0]
Cv[k_][t_] := Cs0/p
Ca[Va_] := Cs0/(1.0 + 1*Va/V0)^m 
Cv[NN][t] := 10000000.0;
Plot[{Ca[Va]}, {Va, 0, 15}, AxesLabel -> {"Va", "Ca"}, 
 PlotRange -> {0, Cs0}, PlotStyle -> {Thickness[.01], Red}, 
 TicksStyle -> Directive["Black", 14], 
 AxesStyle -> {{Thick, Black}, {Thick, Black}}, 
 AxesLabel -> {Style["t", Black, Italic, 30], 
   Style["x,Vin", Black, Italic, 30]}, Frame -> False, 
 PlotRange -> All]
(*non linear inductance*)
L0 = 465; La = 4.65; Is = 3.76;
Ls[k_][t_] := (L0 - La)*(Sech[i[k][t]/Is]^2) + La
La1[Ia_] := (L0 - La)*(Sech[(Ia/Is)]^2) + La
Plot[{La1[Ia]}, {Ia, 0, 100}, AxesLabel -> {"Ia", "La1"}, 
 PlotRange -> {0, L0*1.2}, PlotStyle -> {Thickness[.01], Orange}, 
 TicksStyle -> Directive["Black", 14], 
 AxesStyle -> {{Thick, Black}, {Thick, Black}}, 
 AxesLabel -> {Style["t", Black, Italic, 30], 
   Style["x,Vin", Black, Italic, 30]}, Frame -> False, 
 PlotRange -> All]
Ls[NN][t] := 1.0*10^-8
Ls[k_][t_] := 280.0
(*Equation for the First Section*)
eqi = Table[{-i[k]'[t] + 
      Vs[t]/Ls[k][t] - (Rs/Ls[k][t])*
       i[k][t] - (Rc[k]/Ls[k][t] )*(i[k][t] - i[k + 1][t]) - (V[k][
         t])/Ls[k][t] - (Rl[k]/Ls[k][t] )*(i[k][t]) == 
     0, -V[k]'[t] + (i[k][t] - i[k + 1][t])/Cv[k][t] == 0}, {k, 1, 1}];

(*Equation for the intermediate Section*)
eqs = Table[{-i[k]'[
        t] + (Rc[k - 1]/Ls[k][t]) *(i[k - 1][t] - 
         i[k][t]) + (V[k - 1][t])/
       Ls[k][t] - (Rc[k]/Ls[k][t] )*(i[k][t] - i[k + 1][t]) - (V[k][
         t])/Ls[k][t] - (Rl[k]/Ls[k][t] )*(i[k][t]) == 
     0, -V[k]'[t] + (i[k][t] - i[k + 1][t])/Cv[k][t] == 0}, {k, 2, 
    NN - 1}];
eqpartial = Join[eqi, eqs, eqf];
eqfinal = Flatten[eqpartial];
(*Equation for the finale Section*)
eqf = Table[{-i[k]'[
        t] + (Rc[k - 1]/Ls[k][t] )*(i[k - 1][t] - 
         i[k][t]) + (V[k - 1][t])/
       Ls[k][t] - (Rc[k]/Ls[k][t] )*(i[k][t] ) - (V[k][t])/
       Ls[k][t] - (Rl[k]/Ls[k][t] )*(i[k][t]) == 
     0, -V[k]'[t] + (i[k][t])/Cv[k][t] == 0}, {k, NN, NN}];
eqpartial = Join[eqi, eqs, eqf];
eqfinal = Flatten[eqpartial];
initial1 = Flatten[Table[{i[k][0] == 0., V[k][0] == 0.}, {k, 1, NN}]];
Vlist = Flatten[Table[{V[k][t], i[k][t]}, {k, 1, NN}]];
sol = NDSolve[Join[eqfinal, initial1], Vlist, {t, 0., tmax}, 
   MaxSteps -> Infinity];
sol1 = Flatten[sol];
inputiv = 
  Table[{i[k][t] = i[k][t] /. sol1, V[k][t] = V[k][t] /. sol1}, {k, 1,
     NN}];
outiv = Flatten[inputiv];
V[0][t_] := Vs[t] - Rs*i[1][t];
Vfp = Table[
   V[k][t_] = Rc[k]*(i[k][t] - i[k + 1][t]) + V[k][t], {k, 1, NN - 1}];
V[NN][t_] := Rc[NN]*(i[NN][t]) + V[NN][t]
Pload[t_] := V[NN][t] i[NN][t]
Pint[t_] := Vs[t] i[1][t]
VoltFim = 
 ListPlot[outiv, PlotRange -> All, 
  PlotStyle -> {AbsoluteThickness[1.4], RGBColor[0, 0, 1], 
    Thickness[0.008]}, FrameLabel -> {"Time(ns)", "Voltage(kV)"}, 
  Joined -> True, GridLines -> {Automatic, Automatic}, 
  FrameTicks -> {Automatic, Automatic}, Frame -> True, 
  LabelStyle -> Directive[Black, 17]]
Show[VoltVs, VoltFim]

the plot is empty, please i need help

The NDSolve worked for me, once I first made the following correction in your code:

Resl_pair = Table[Rl[k] = 0.0, {k, 2, NN, 2}];
POSTED BY: Frank Iannarilli

Hi Frank... Please show your graph.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract