How to solve ODEs with symbolic variables using ode45?
Show older comments
I'm trying to solve a system of ODE with 4 equations with symbolic variable as the input. I splitted the code into 3 files.
file name : parameter_pml_freerun0.m
clear
global f Pole ws Rs Rr Lr Ls Lm VLL Tload J B Las Lar vqs vds vqr vdr
f = 50; %frek listrik
Pole = 4; %jumlah pole
ws = 2*f*pi; %kecepatan elektrikal sinkron dalam rad/s
Rs = 1.278; %resistansi stator
Rr = 3.93033; %resistansi rotor
Lr = 0.009549; %induktansi rotor
Ls = Lr; %induktansi stator
Lm = 0.370842; %induktansi magnetisasi
VLL = 380; %tegangan line to line terminal motor
Tload = 11.852;
J = 0.1;
B = 0;
syms t
Las = Ls+Lm; Lar = Lr+Lm;
%transformasi tegangan abc to dq0
Vm = VLL*sqrt(2)/sqrt(3); %tegangan puncak fasa tanah
Vabc = Vm.*[sin(t); sin(t - 2*pi/3); sin(t + 2*pi/3)];
Park = (2/3).*[cos(0) cos(0 - 2*pi/3) cos(0 + 2*pi/3); sin(0) sin(0 - 2*pi/3) sin(0 + 2*pi/3); 1/2 1/2 1/2];
Vqd0 = Park*Vabc;
vqs = simplify(Vqd0(1,1)); vds = simplify(Vqd0(2,1)); vqr = 0; vdr = 0;
I used this file to store induction motor parameter and do Park transformation in stator reference frames, the transformation returns vqs and vds as symbolic variables
>> vqs
vqs =
(5458304707397847*sin(t))/17592186044416
>> vds
vds =
(5458304707397847*cos(t))/17592186044416
I stored the set of ODEs in the second file
function [diffy_eqn] = diffy_eqn(ti,statev)
global Pole ws Rs Rr Lm Tload J B Las Lar vqs vds vqr vdr
lamqs = statev(1);
lamds = statev(2);
lamqr = statev(3);
lamdr = statev(4);
wr = statev(5);
th = statev(6);
idr = (Lm*lamds - Las*lamdr)/(Lm^2 - Lar*Las);
iqr = (Lm*lamqs - Las*lamqr)/(Lm^2 - Lar*Las);
iqs = (Lm*lamqr - Lar*lamqs)/(Lm^2 - Lar*Las);
ids = (Lm*lamdr - Lar*lamds)/(Lm^2 - Lar*Las);
s1 = (vqs - ws*lamds - Rs*iqs);
s2 = (vds + ws*lamqs - Rs*ids);
s3 = (vqr - (ws - wr)*lamdr - Rr*iqr);
s4 = (vdr + (ws - wr)*lamqr - Rr*idr);
Te = (3/2)*(Pole/2)*(lamqr*idr - lamdr*iqr);
s5 = (Pole/2)*(Te - Tload - B*wr)/J;
s6 = ws;
diffy_eqn = [s1 s2 s3 s4 s5 s6]';
The third file is where i stored the solver
clear
close all
parameter_pml_freerun0
time = [0 7]';
state0 = [0 0 0 0 0 0]';
[tout,yout] = ode45('diffy_eqn',time, state0);
lamqs = yout(:,1);
lamds = yout(:,2);
lamqr = yout(:,3);
lamdr = yout(:,4);
wr = yout(:,5);
th = yout(:,6);
idr = (Lm*lamds - Las*lamdr)/(Lm^2 - Lar*Las);
iqr = (Lm*lamqs - Las*lamqr)/(Lm^2 - Lar*Las);
iqs = (Lm*lamqr - Lar*lamqs)/(Lm^2 - Lar*Las);
ids = (Lm*lamdr - Lar*lamds)/(Lm^2 - Lar*Las);
T = (3/2).*(Pole/2).*Lm*(iqs.*idr - ids.*iqr);
ias = cos(th).*ids - sin(th).*iqs;
ibs = cos(th - 2.*pi/3.).*ids - sin(th - 2.*pi/3.).*iqs;
ics = cos(th + 2.*pi/3.).*ids - sin(th + 2.*pi/3.).*iqs;
vas = cos(th).*vds - sin(th).*vqs;
vbs = cos(th - 2.*pi/3.).*vds - sin(th - 2.*pi/3.).*vqs;
vcs = cos(th + 2.*pi/3.).*vds - sin(th + 2.*pi/3.).*vqs;
The solver returned this error code
free_accel
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in free_accel (line 7)
[tout,yout] = ode45('diffy_eqn',time, state0);
How can I make the ODEs solvable? I've tried using matlabFunction to the ODEs but that didn't work. Thank you
Accepted Answer
More Answers (0)
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!