How to solve an integral equation in simulink?

Hi,
I need to solve the following equation in simulink:
I have ξ (= xi) as an input and need iav as an output to forward it to other blocks. I tried to use the MATLAB function block, but the code I've written doesn't work.
function iav = fcn(xi)
syms xi phi iav
fun = 1/(sqrt(1-(1-phi^(3/2))*((1-iav)*xi)^(3/2)));
eqn = (1-iav)*int(fun,phi,0,1)==1;
iav = solve(eqn,iav);
end
Any help would be much appreciated. Thanks in advance.
Leon

 Accepted Answer

Hi,
Please let us know what error exactly you are getting while using Function block in Simulink.
My Initial guess is that error might be coming because iav is returning as empty symbolic variable . I tried to run the your function on your end and the value you passing to the function is not getting assigned to the symbolic Variable xi.
Also it is advised to convert the iav to double before returning.
function t = fcn(txi)
syms xi phi iav
xi = txi;
fun = 1/(sqrt(1-(1-phi^(3/2))*((1-iav)*xi)^(3/2)));
eqn = (1-iav)*int(fun,phi,0,1)==1;
iav = vpasolve(eqn,iav);
t = double(iav);

3 Comments

Hi,
first of all, thanks a lot for you answer. I tried to run the script you suggested and it still gives me multiplie errors:
First is
Function 'syms' not supported for code generation.
and because of that the variables xi, phi and iav are not defined then.
And then there is also another error called:
Errors occurred during parsing of MATLAB function
and a few more like:
Simulink cannot determine sizes and/or types of the outputs for block
['Environment_Model/Electrodynamic Force/Subsystem/Fraction of Isc ' ...
'iav/If Action Subsystem1/MATLAB Function'] due to errors in the block body,
or limitations of the underlying analysis. The errors might be inaccurate.
Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Honestly, I have no idea how to solve them. Hopefully that's what you need.
I really hope you can help me with that.
Hi ,
It seems to be known issue with using syms in MATLAB function block. There is one workaround though, that is using the sym and vpassolve in another function and call that file as extrinsic.
Using that example I created a separate .m file 'fcn.m':
function y = fcn(u)
syms xi phi iav
xi = u;
fun = 1/(sqrt(1-(1-phi^(3/2))*((1-iav)*xi)^(3/2)));
eqn = (1-iav)*int(fun,phi,0,1)==1;
iav = vpasolve(eqn,iav);
y = double(iav);
and then I call this file as extrinsic:
MATLAB function block call:
function y = fcn1(u)
coder.extrinsic('fcn');
y = 0;
y = fcn(u);
Using this I am able to remove the errors .
On another note the simulation will be very slow because the symbolic integration takes a lot of time
Thanks
Hi,
Thanks a lot. I was able to remove the errors too. But, your right. The simulation now just takes forever because of that.
Can you think of any other solution to solve this problem? Maybe an entirely different approach which would be quicker?

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!