matlabFunction on symbolic experssion and the Error using symengine

Hello
I have a mix double integral and partial differential expression and I want to solve it by symbolic math in matlab.
My code below written to solve the equation. But matlabFunction() does not work on it and gives me an error.
I would be appreciated if anybody could help me. I tried the numerical way to solve this expression but I could not find the right result. The only way that I think work is using symbolic math. Any idea and help is appreciated.
Here is my code:
syms t z
w=1.11;
T=1.2;
zita=0.5;
a=1;
b=1;
d=0;
%%
teta=exp(-((1-t/T)*(t/T))^(-w));
phi=int(teta)/int(teta,0,T);
Y1=[1;1]+[1;2]*phi;
Y2=[2;1]+[1;1]*phi;
eta0=Y1+(z-zita)*Y2;
F=[(1/a)*(diff(eta0(1,1),t)-eta0(2,1)*eta0(1,1)); ...
(1/b)*(diff(eta0(2,1),t)-d*eta0(2,1))];
int1=int(F,z)-int(F,z,0,zita);
etaAux=int(int1,z)-int(int1,z,0,zita);
eta=eta0+etaAux;
etaD=diff(eta,z);
fun=matlabFunction(etaD);
After running the code, I got this error:
Error using symengine
Unable to evaluate to Boolean.
Error in sym/matlabFunction>mup2mat (line 404)
res = mupadmex('symobj::generateMATLAB',r.s,ano,spa,0);
Error in sym/matlabFunction>mup2matcell (line 374)
r = mup2mat(c{1},true,sparseMat);
Error in sym/matlabFunction (line 188)
body = mup2matcell(funs, opts.Sparse);
Could you please help me with this issue?
etaD is 2by1 and matlabFunction() works on etaD(2,1) but does not work on etaD(1,1) and gives me the same error as above.

1 个评论

It has something to do with the square of an integral. It doesn't matter if it is numerator or denominator but it does matter that it is squared

请先登录,再进行评论。

 采纳的回答

It appears to be a bug. I might look into the internal code when I am more awake, but that code is difficult to read and debug.
In the meantime, there is a workaround. It takes a bit of time to compute it, but it gets there.
The workaround is instead of
matlabFunction(etaD)
use
matlabFunction(rewrite(etaD, 'sincos'))
You will have to wait a bit for it to compute the rewrite()
Do not simplify() the results of the rewrite() or else you get back to code that has the problem

4 个评论

Thank you so much for your answer.
It works and does not have any error but, the result is not true.
I compare it with matlabFunction(etaD(2,1)) ( which it works):
fun1=matlabFunction(etaD(2,1));
fun1(0.5,0.5)
ans=
-0.55
fun2=matlabFunction(rewrite(etaD(2,1),'sincos'));
fun2(0.5,0.5)
ans=
NaN
I would be really appreciated if you help me and take a look at the code any time you are free.
Many thanks in advance
Debugging this further, I see that it occurs under the circumstance that you have an int() to a power, and the int() does not have a closed form, and the int() expression can be evaluated to a floating point number.
I am experimenting with using vpa() on etaD, but something odd seems to be happening.
Yes, you can matlabFunction(vpa(etaD))
I will file a bug report with Mathworks.
IT WORKS!
Thank you so much for your help and time.
I appreciate your kind guidance.
Best regards

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

产品

版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by