Error using symengine Unable to convert expression into double array.

What could be the problem with the code below? I can't get numerical answer for the error_dvd
clear all
syms a n lamb th h0 l hn deltal
eqd=n*lamb/(sin(a-th)-sin(a));
eqa=1/2*atan(h0/l);
eqth=2*a-atan(hn/l);
d_a=diff(eqd,a);
a_l=diff(eqa,l);
d_th=diff(eqd,th);
th_l=diff(eqth,l);
th_a=diff(eqth,a);
a_h0=diff(eqa,h0);
th_hn=diff(eqth,hn);
deltal=0.01;
deltah0=0.006;
deltahn=0.006;
a=1/2*atan(h0/l);
th=atan(h0/l)-atan(hn/l)
n=-1;
h0=0.26;
hn=0.079;
lamb=405*10^(-9);
l=0.15;
ltermi=abs((d_a*a_l+d_th*th_l+d_th*th_a*a_l))*abs(deltal);
h0termi=abs(d_a*a_h0+d_th*th_a*a_h0)*abs(deltah0);
hntermi=abs(d_th*th_hn)*abs(deltahn);
error_dvd(1)=double(subs(ltermi+h0termi+hntermi))
d_dvd(1)=n*lamb/(sin(atan(hn/l)-1/2*atan(h0/l))-sin(1/2*atan(h0/l)))

 채택된 답변

Running:
ReasonsDoubleIsNotPossible = symvar(subs(ltermi+h0termi+hntermi))
just before ‘error_dvd’ produces:
ReasonsDoubleIsNotPossible =
[ h0, hn, l]
The presence of symbolic variables in that expression prevents the double evaluation. Those variables nust have numeric values.
The problem is with respect to the order of the statements.
This does what you want:
syms a n lamb th h0 l hn deltal
eqd=n*lamb/(sin(a-th)-sin(a));
eqa=1/2*atan(h0/l);
eqth=2*a-atan(hn/l);
d_a=diff(eqd,a);
a_l=diff(eqa,l);
d_th=diff(eqd,th);
th_l=diff(eqth,l);
th_a=diff(eqth,a);
a_h0=diff(eqa,h0);
th_hn=diff(eqth,hn);
deltal=0.01;
deltah0=0.006;
deltahn=0.006;
n=sym(-1);
h0=sym(0.26);
hn=sym(0.079);
lamb=sym(405*1E-9);
l=sym(0.15);
a=1/2*atan(h0/l);
th=atan(h0/l)-atan(hn/l)
ltermi=abs((d_a*a_l+d_th*th_l+d_th*th_a*a_l))*abs(deltal);
h0termi=abs(d_a*a_h0+d_th*th_a*a_h0)*abs(deltah0);
hntermi=abs(d_th*th_hn)*abs(deltahn);
error_dvd(1)=double(subs(ltermi+h0termi+hntermi))
d_dvd(1)=n*lamb/(sin(atan(hn/l)-1/2*atan(h0/l))-sin(1/2*atan(h0/l)))
and with the addition of the vpa call:
d_dvd(1)=vpa(n*lamb/(sin(atan(hn/l)-1/2*atan(h0/l))-sin(1/2*atan(h0/l))))
produces:
error_dvd =
57.3505e-009
d_dvd =
0.00000075120302179556347730706133365097
.

댓글 수: 2

My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2020년 5월 3일

댓글:

2020년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by