xlogI125’s blog

パソコン作業を効率化したい

電流I0

正確な内容は電気回路論や交流理論などの教科書を参照してください

集中定数回路で単一周波数の定常状態のみを考慮

定常状態の基本波のみを考慮する

\Large
\begin{align*}
i(x,t)
&= f(x)g(t) \\
&= kg(t) \\
&= \frac{a_0}{2} + \sum_{n=1}^\infty \left( a_n \cos\left(n \omega_{\mathrm{e}1} t \right) + b_n \sin\left(n \omega_{\mathrm{e}1} t \right) \right) \\
&= I_0 + \sum_{n=1}^\infty \sqrt{2} I_n \sin \left( n \omega_{\mathrm{e}1} t + \varphi_{\mathrm{e}n} \right) \\
&= \sqrt{2} I_1 \sin \left( \omega_{\mathrm{e}1} t + \varphi_{\mathrm{e}1} \right)
\end{align*}

電気回路の計算式での取り扱いが便利になるよう重ね合わせる

\Large
\begin{align*}
I(t)
&= \left( A + \mathrm{j} B \right) i(t) + \left( C + \mathrm{j} D \right) \frac{\mathrm{d}}{\mathrm{d}t}i(t) \\
&= \sqrt{2} I_1 \left(\cos \left( \omega_{\mathrm{e}1} t + \varphi_{\mathrm{e}1} \right) + \mathrm{j}\sin \left( \omega_{\mathrm{e}1} t + \varphi_{\mathrm{e}1} \right) \right) \\
&= \sqrt{2} I_1 \mathrm{e}^{\mathrm{j}\varphi_{\mathrm{e}1}} \mathrm{e}^{\mathrm{j} \omega_{\mathrm{e}1} t}
\end{align*}

フェーザ表示

三相回路における電流をフェーザ表示で考えることにする

\Large
\begin{align*}
\dot{I}_{\mathrm{a}}
&= I_{\mathrm{a}} \left( \cos \varphi_\mathrm{a} + \mathrm{j} \sin \varphi_\mathrm{a} \right) \\
&= I_{\mathrm{a}} \mathrm{e}^{\mathrm{j} \varphi_\mathrm{a} }
\end{align*}

ベクトルオペレータ

\Large
\begin{equation*}
a = \mathrm{e}^{\left(2\pi/3\right)\mathrm{j}}
\end{equation*}

三相3線式における各相の電流が変数I0, I1, I2の重ね合わせで表現できるとする

\Large
\begin{equation*}
\left\{
\begin{aligned}
\dot{I}_{\mathrm{a}}
&= &{} &\dot{I}_{\mathrm{0}} &{} &+ &{}     &\dot{I}_{\mathrm{1}} &{} &+ &{}  &\dot{I}_{\mathrm{2}} \\
%
\dot{I}_{\mathrm{b}}
&= &{} &\dot{I}_{\mathrm{0}} &{} &+ &a^{-1} &\dot{I}_{\mathrm{1}} &{} &+ &a   &\dot{I}_{\mathrm{2}} \\
%
\dot{I}_{\mathrm{c}}
&= &{} &\dot{I}_{\mathrm{0}} &{} &+ &a^{-2} &\dot{I}_{\mathrm{1}} &{} &+ &a^2 &\dot{I}_{\mathrm{2}}
\end{aligned}
\right.
\end{equation*}

指数部分を書き直す

\Large
\begin{equation*}
\left\{
\begin{aligned}
\dot{I}_{\mathrm{a}}
&= &{} &\dot{I}_{\mathrm{0}} &{} &+ &{}     &\dot{I}_{\mathrm{1}} &{} &+ &{} &\dot{I}_{\mathrm{2}} \\
%
\dot{I}_{\mathrm{b}}
&= &{} &\dot{I}_{\mathrm{0}} &{} &+ &a^{2} &\dot{I}_{\mathrm{1}} &{} &+ &a   &\dot{I}_{\mathrm{2}} \\
%
\dot{I}_{\mathrm{c}}
&= &{} &\dot{I}_{\mathrm{0}} &{} &+ &a     &\dot{I}_{\mathrm{1}} &{} &+ &a^2 &\dot{I}_{\mathrm{2}}
\end{aligned}
\right.
\end{equation*}

教科書などで登場する行列表記

\Large
\begin{equation*}
\begin{pmatrix}
\dot{I}_{\mathrm{a}} \\
\dot{I}_{\mathrm{b}} \\
\dot{I}_{\mathrm{c}}
\end{pmatrix}
=
\begin{pmatrix}
1 & 1   & 1 \\
1 & a^2 & a \\
1 & a   & a^2
\end{pmatrix}
\begin{pmatrix}
\dot{I}_{\mathrm{0}} \\
\dot{I}_{\mathrm{1}} \\
\dot{I}_{\mathrm{2}}
\end{pmatrix}
\end{equation*}

変数I0, I1, I2

\Large
\begin{equation*}
\begin{pmatrix}
\dot{I}_{\mathrm{0}} \\
\dot{I}_{\mathrm{1}} \\
\dot{I}_{\mathrm{2}}
\end{pmatrix}
=
\cfrac{1}{3}
\begin{pmatrix}
1 & 1   & 1   \\
1 & a   & a^2 \\
1 & a^2 & a
\end{pmatrix}
\begin{pmatrix}
\dot{I}_{\mathrm{a}} \\
\dot{I}_{\mathrm{b}} \\
\dot{I}_{\mathrm{c}}
\end{pmatrix}
\end{equation*}

変数I0

\Large
\begin{align*}
I_{\mathrm{0}}
&= \frac{1}{3} \lvert \dot{I}_{\mathrm{a}} + \dot{I}_{\mathrm{b}} + \dot{I}_{\mathrm{c}} \rvert \\
&= \frac{1}{3} \lvert \dot{i}_{\mathrm{a}} + \dot{i}_{\mathrm{b}} + \dot{i}_{\mathrm{c}} \rvert I_{3\phi\mathrm{BASE}} \\
&= i_{\mathrm{0}} \frac{S_{3\phi\mathrm{BASE}}}{3 E_{3\phi\mathrm{BASE}}}
\end{align*}

変圧器(Y結線)の中性点に流れ込む電流Ig

\Large
\begin{align*}
I_{\mathrm{g}}
&= \lvert \dot{I}_{\mathrm{a}} + \dot{I}_{\mathrm{b}} + \dot{I}_{\mathrm{c}} \rvert \\
&= 3 I_0
\end{align*}

ファイル作成時に通知領域にアイコンを表示 3

メモ

NotifyIconにおけるContextMenuStripGUIが固まらないようにするため、試しにForm表示時のみContextMenuStripを設定する。

スクリプト

NotifyIconにおけるContextMenuStripの動作確認が目的

# PowerShell 5.1, Windows 11 (2024年1月頃)
Set-StrictMode -Version Latest

$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
$VerbosePreference = [System.Management.Automation.ActionPreference]::Continue

# Register-ObjectEventコマンドレットの使用ではなくC#でイベントハンドラを追加
Add-Type -Language CSharp -TypeDefinition @'
namespace MyNS {
  public abstract class MyCls {
    public static void AddCreated(dynamic obj, dynamic lambdaMethod) {
      obj.Created += lambdaMethod;
    }
    public static void RemoveCreated(dynamic obj, dynamic lambdaMethod) {
      obj.Created -= lambdaMethod;
    }
  }
}
'@ -ReferencedAssemblies Microsoft.CSharp

Add-Type -AssemblyName System.Drawing, System.Windows.Forms

$watcher = [System.IO.FileSystemWatcher]::new()
$form = [System.Windows.Forms.Form]::new()

# SynchronizingObjectプロパティ
$watcher.SynchronizingObject = $form

$watcher.Path = "${env:USERPROFILE}\Desktop"
$watcher.Filter = "*"
$watcher.IncludeSubdirectories = $true
$watcher.NotifyFilter = [System.IO.NotifyFilters]::FileName
$watcher.EnableRaisingEvents = $true

$lambdaMethod = [System.IO.FileSystemEventHandler]{
  param ([object]$sender, [System.IO.FileSystemEventArgs]$e)
  # ローカル変数を表示
  Get-Variable -Scope Local | Out-String -Width 80 | Write-Verbose
  # $this と $_ の確認
  Write-Host "`$this と `$sender : $([object]::Equals($this, $sender))" -ForegroundColor Cyan
  Write-Host "$($sender | Format-List | Out-String)" -ForegroundColor Cyan
  Write-Host "`$_    と `$e      : $([object]::Equals($_, $e))" -ForegroundColor Green
  Write-Host "$($e      | Format-List | Out-String)" -ForegroundColor Green
  # スコープを指定して変数を変更
  $global:numCreated++
  Write-Host "numCreated: $($global:numCreated)"
}

$numCreated = 0

$notify = [System.Windows.Forms.NotifyIcon]::new()
$notify.Icon = [System.Drawing.SystemIcons]::Exclamation
$notify.Text = "通知領域アイコン"
$notify.Visible = $true

# ContextMenuStrip
$cm = [System.Windows.Forms.ContextMenuStrip]::new()
$cm.Items.Add("フォームのCloseメソッドを呼び出す", $null, [System.EventHandler]{
  $global:form.Close()
})

# 通知領域アイコンのクリック時にフォームのShowDialogメソッドを呼び出す
$notify.add_MouseClick([System.Windows.Forms.MouseEventHandler]{
  if ($global:form.Visible -eq $false) {
    $global:form.ShowDialog()
  }
})

# フォームのLoadイベント発生時にイベントハンドラを追加
$form.add_Load([System.EventHandler]{
  Write-Verbose "form: Load" -Verbose
  [MyNS.MyCls]::AddCreated($watcher, $global:lambdaMethod)
  $notify.ContextMenuStrip = $cm
})

# フォームのFormClosingイベント発生時にイベントハンドラを削除
$form.add_FormClosing([System.Windows.Forms.FormClosingEventHandler]{
  Write-Verbose "form: Closing" -Verbose
  [MyNS.MyCls]::RemoveCreated($watcher, $global:lambdaMethod)
  $notify.ContextMenuStrip = $null
})

# コンソール上で Ctrl + C を押した後に
# FileSystemWatcher.Createdイベントが発生するとエラーになる

$form.ShowDialog()

PowerShell練習 [System.Action]{} # lambda_method

ScriptBlockDelegateに変換しようとするとlambda_methodになる様子

# PowerShell 5.1, Windows 11 (2023年12月頃)
$lambdaMethod = [System.IO.FileSystemEventHandler]([ScriptBlock]::Create(""))
$lambdaMethod | Format-List

引数の確認

# PowerShell 5.1, Windows 11 (2023年12月頃)
$lambdaMethod = [System.IO.FileSystemEventHandler]{}
$lambdaMethod | Get-Member -Name Invoke

$argsの確認

# PowerShell 5.1, Windows 11 (2023年12月頃)
$lambdaMethod = [System.IO.FileSystemEventHandler]{
  Get-Variable -Scope Local -Name args | Out-String | Write-Host
}
$lambdaMethod.Invoke($null, $null)

引数の確認

# PowerShell 5.1, Windows 11 (2023年12月頃)
([System.Func[string, string, string]]{}).Invoke

paramを使う場合の確認

# PowerShell 5.1, Windows 11 (2023年12月頃)
([System.Func[string, string, string]]{
  param ([string]$arg1, [string]$arg2)
  $arg1 + $arg2 | Write-Host
  Get-Variable -Scope Local | Out-String -Width 80 | Write-Verbose -Verbose
}).Invoke("abc", "def")

List<T>.Sort(Comparison<T>)の確認

# PowerShell 5.1, Windows 11 (2023年12月頃)

Add-Type -Language CSharp -TypeDefinition @'
using System.Runtime.InteropServices;
namespace Win32API {
  public class Shlwapi {
    [DllImport("Shlwapi.dll", EntryPoint = "StrCmpLogicalW", CharSet = CharSet.Unicode)]
    public static extern int StrCmpLogicalW(
      [MarshalAs(UnmanagedType.LPWStr)] string psz1, 
      [MarshalAs(UnmanagedType.LPWStr)] string psz2
    );
  }
}
'@

$psObjList = [System.Collections.Generic.List[PSObject]][PSObject[]]@(Get-ChildItem)

$psObjList | Select-Object -Property Name | ForEach-Object { Write-Host $_.Name -ForegroundColor Green }
<#
文書1.txt
文書10.txt
文書100.txt
文書5.txt
文書50.txt
#>

$cmp = [System.Comparison[PSObject]]{
  param ([PSObject]$x, [PSObject]$y)
  return [Win32API.Shlwapi]::StrCmpLogicalW($x.Name, $y.Name)
}

$psObjList.Sort($cmp)

$psObjList | Select-Object -Property Name | ForEach-Object { Write-Host $_.Name -ForegroundColor Cyan }
<#
文書1.txt
文書5.txt
文書10.txt
文書50.txt
文書100.txt
#>