0
$\begingroup$

Working on ODE systems solution with NDSolve[] I decided to try to replace system of equations like:

{f1'[t] == a*f1[t] + b*f2[t] + e[t] , f2'[t] == c*f1[t] + d*f2[t] + g[t], f1[0] == f2[0] == 0}

with vector ODE like:

{f'[t] == A.f[t] + b[t], f[t] == {0,0}}

where

A == {{a,b},{c,d}}
f[t] == {f1[t],f2[t]}
b[t] == {e[t],g[t]} .

That is the theory. My notebook code seems like that:

θ[x_] := Boole[x >= 0]
R := 500
L := 0.2
C1 := 2*10^(-10)
Rl := 10^3
T := 10^(-3)
Um := 10
t1 := T/2
t2 := T/3
t3 := T/6
u1[t_] := Um/t3*(t*θ[t] - (t - t3) θ[t - t3] - (t - t2) θ[t - t2] + (t - t1) θ[t - t1])
A := {{-(R*C1)^(-1), -1/C1}, {1/L, -Rl/L}}
b[t_] := {u1[t]/(R*C1), 0}
numsltn = NDSolve[{d'[t] == A.d[t] + b[t], d[0] == {0, 0}}, d, {t, -T, T}]
(*d[t] == {uC[t],iL[t]} is incarnation of f[t] == {f1[t],f2[t]}*)
Plot[Projection[b[t], {1, 0}], {t, -T, T}]
uC[t_] := Evaluate[Projection[d[t], {1, 0}] /. numsltn]
iL[t_] := Evaluate[Projection[d[t], {0, 1}] /. numsltn]
Plot[{uC[t], iL[t]*1000}, {t, -T, T}, PlotRange -> {{-1.03 T, 1.03 T}, {-0.225 Um, 1.025 Um}}]

When I try to execute this code, I get this error:

Projection: The first or second argument or both are not vectors, or they are not vectors of equal length.

4 times in a row. What is much more strange, after error messages I get correct plots: My output

So I would like to ask... What I do wrong? And why I get good output after errors? Thanks in advance.

P.S. I'm real noob in WM so please do not judge strictly if answer turns to be "on hand".

$\endgroup$

1 Answer 1

2
$\begingroup$

Try NDSolveValue and ParametricPlot

dN = NDSolveValue[{d'[t] == A . d[t] + b[t], d[0] == {0, 0}},d, {t, -T, T}]
ParametricPlot[dN[t] {1, 1000}(*scaling*), {t, -T, T}, AspectRatio -> 1]

enter image description here

$\endgroup$
1
  • $\begingroup$ Good time of day, thank you for your answer, but for some reasons I'm not sure that this problem solving way that fits the bill for me: 1. I don't need parametric plot, I need plot with curves uC[t] and iL[t] exactly. 2. I would like to learn how to work with Projection[] and {d -> InterpolatingFunction}. $\endgroup$ Commented May 8, 2021 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.