State derivatives returned by S-function 'BUCKchap3_6plant' in 'BUCKchap3_6/S-Function' during flag=1 call must be a real vector of length 2
17 ビュー (過去 30 日間)
古いコメントを表示
error:State derivatives returned by S-function 'BUCKchap3_6plant' in 'BUCKchap3_6/S-Function' during flag=1 call must be a real vector of length 2。
function [sys,x0,str,ts]=BUCKchap3_6plant(t,x,u,flag) switch flag, case 0 [sys,x0,str,ts]=mdlInitializeSizes; case 1 sys=mdlDerivatives(t,x,u); case 3 sys=mdlOutputs(t,x,u); case {2, 4, 9 } sys = []; otherwise error(['Unhandled flag = ',num2str(flag)]); end
function [sys,x0,str,ts]=mdlInitializeSizes sizes = simsizes; sizes.NumContStates = 2; sizes.NumDiscStates = 0; sizes.NumOutputs = 2; sizes.NumInputs = 1; sizes.DirFeedthrough = 1; sizes.NumSampleTimes = 0; sys=simsizes(sizes); x0=[0 0]; str=[]; ts=[];
function sys=mdlDerivatives(t,x,u) L=1e-3; R=20; C=1000e-6; Vin=50;
sys(1)=(-x(2)+Vin*u(1))/L; sys(2)=x(1)/C-x(2)/C/R;
function sys=mdlOutputs(t,x,u) sys(1)=x(1); sys(2)=x(2);
1 件のコメント
Walter Roberson
2018 年 11 月 5 日
Just before
sys(1)=(-x(2)+Vin*u(1))/L; sys(2)=x(1)/C-x(2)/C/R;
Add
assert(all(imag(u)==0), 'u is imaginary or nan')
回答 (2 件)
FUN S
2018 年 11 月 5 日
編集済み: Walter Roberson
2020 年 6 月 16 日
2 件のコメント
Walter Roberson
2020 年 6 月 16 日
"Fun S": I reformatted your code to make it readable. Please check it to ensure that I correctly interpreted the comment positions.
参考
カテゴリ
Help Center および File Exchange で Audio I/O and Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!