Simulink mex s-function returns different results for equal input
1 view (last 30 days)
Show older comments
My s-function has two input arguments: param (parameter of the system described by the s-function) and ic0 (initial conditions). Both are given to the function as vectors.
THE PROBLEM: Depending on how the vector param was initialized, the function call fails or runs just fine. The code is below. The function isequal(p1, p2) always returns true, which means that there must be some difference which isequal() doesnt recognize or some problem with the memory?? (the vectors p1 and p2 only contain values of type double)
Can someone help with that? I'm running out of ideas! thanks a lot!
clear all; close all; clc;
loadGeoParams %loading geometric parameters like lA1, lA2, ... and storing them in vector param_geo
loadDynParams %loading dynamic parameters like g, i_G1, i_G2, ... and storing them in vector param_dyn
p1 = [param_geo param_dyn]; %using this parameter vector, leads to a problem while running simulink
p2 =[lA1 lA2 lA3 lA4 lA5 lA6 lA7 lA8 lA9 lA10 wRail g ... %using this parameter vector, everything works just fine
i_G1 i_G2 i_G3 i_G4 i_G5 i_G6 i_G7 i_G8 ...
J_A3_A J_A3_B J_A3_C J_A4_A J_A4_B J_A4_C ...
J_A5_A J_A5_B J_A5_C J_A6_A J_A6_B J_A6_C ...
J_A7_A J_A7_B J_A7_C J_A8_A J_A8_B J_A8_C ...
J_A9_A J_A9_B J_A9_C J_A10_A J_A10_B J_A10_C ...
J_M1_A J_M1_B J_M1_C J_M2_A J_M2_B J_M2_C ...
J_M3_A J_M3_B J_M3_C J_M4_A J_M4_B J_M4_C ...
J_M5_A J_M5_B J_M5_C J_M6_A J_M6_B J_M6_C ...
J_M7_A J_M7_B J_M7_C J_M8_A J_M8_B J_M8_C ...
J_M9_A J_M9_B J_M9_C J_M10_A J_M10_B J_M10_C ...
m_M1 m_M2 m_M3 m_M4 m_M5 m_M6 m_M7 m_M8 m_M9 m_M10 ...
m_A1 m_A2 m_A3 m_A4 m_A5 m_A6 m_A7 m_A8 m_A9 m_A10 m_E ...
dv_1 dv_2 dv_3 dv_4 dv_5 dv_6 dv_7 dv_8 dv_9 dv_10 ...
dc_1 dc_2 dc_3 dc_4 dc_5 dc_6 dc_7 dc_8 dc_9 dc_10 e];
clearvars -except p1 p2
isequal(p1,p2) %always returns true
test = 1; %use p1 or p2 where p1 yields an error in the simulation and with p2 everything works fine
if test == 1
param = p1;
else
param = p2;
end
Ta = 400e-6; %sampling time for simulink
Tsim = 11; %simulation time for simulink
ic0 = zeros(1,20); %set initial conditions to 0;
sim testEqPparams %simulink file consists of one block with a mex s-function with the two inputs param and ic0
%which takes param and ic0 as input.
Output when using p1:
_________________________________________________________________________________________
ans =
logical
1
Error using testequality (line 43)
Derivative of state '11' in block 'testEqPparams/S-Function' at time 0.0 is not finite. The simulation will be
stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing
the fixed step size or by tightening the error tolerances)
_________________________________________________________________________________________
0 Comments
Answers (0)
See Also
Categories
Find more on Block and Blockset Authoring 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!