How to solve an integral equation in simulink?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Deepak Meena
2021년 3월 17일
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
Deepak Meena
2021년 3월 17일
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.
Refer to this example How to use symbolic variables and functions (Syms) in a Simulink Matlab Function?
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);
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!