A Differential Equations model with S-function Level 2
Afficher commentaires plus anciens
Hi, I would like to model the following system using a S-function level 2 block:
dV_dt=w*(pi*(d^2)/4)*(R+sin(theta)+(R^2)*sin(theta)*cos(theta)/(L*sqrt(1-(R^2)*(sin(theta)^2)/(L^2))))
w, d, R, THETA, and L are inputs, parameters or constants. I have written the following file but I do not obtain the expected results. I just want to obtain V, and dV_dt as outputs. Another question is how I can define R, L, d as constants inside the S-function instead of defining as parameters.
file:
function GeometriaCil(block) % Level-2 MATLAB file S-Function for basic integrator demo. % Copyright 1990-2009 The MathWorks, Inc.
setup(block);
%endfunction
function setup(block)
%%Register number of dialog parameters
block.NumDialogPrms = 3;
%%Register number of input and output ports
block.NumInputPorts = 2;
block.NumOutputPorts = 1;
%%Setup functional port properties to dynamically
%%inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DirectFeedthrough = false;
block.OutputPort(1).Dimensions = 1;
%%Set block sample time to continuous
block.SampleTimes = [0 0];
%%Setup Dwork
block.NumContStates = 1;
%%Set the block simStateCompliance to default (i.e., same as a built-in block)
block.SimStateCompliance = 'DefaultSimState';
%%Register methods
block.RegBlockMethod('InitializeConditions', @InitConditions);
block.RegBlockMethod('Outputs', @Output);
block.RegBlockMethod('Derivatives', @Derivative);
%endfunction
function InitConditions(block)
%%Initialize Dwork
block.ContStates.Data(1) = 0;
%endfunction
function Output(block)
block.OutputPort(1).Data = block.ContStates.Data;
%endfunction
function Derivative(block) R = block.DialogPrm(1).Data; L = block.DialogPrm(2).Data; d = block.DialogPrm(3).Data;
theta = block.InputPort(1).Data;
w = block.InputPort(2).Data;
f1=(pi*(d^2)/4)*(R+sin(theta)+(R^2)*sin(theta)*cos(theta)/(L*sqrt(1-(R^2)*(sin(theta)^2)/(L^2))));
block.Derivatives.Data(1) = f1*w; %dV_dt
%endfunction
Greetings,
Carlos
Réponses (0)
Catégories
En savoir plus sur General Applications dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!