Unable to convert expression into double array.
Mostrar comentarios más antiguos
I'm running a code which gives me the error at certain combanation of parameter: "Unable to convert expression into double array."
I defined the function "answer" as follows:
function F=answer(t,k,x,N,d,v1)
syms x;
F(1)=-t(3)+((t(2)^2-t(1)^2)*k/(2*d))^(1/N);
F(2)=int(1/sqrt(t(1)^2+(2*d*(t(3)^N)/k*N)+2*d*(N-1)*x^N/k*N),x,t(3),1)-3*k*t(1)/2*v1+t(3)/t(1);
F(3)=int(1/sqrt(t(1)^2+(2*d*(t(3)^N)/k*N)+2*d*(N-1)*x^N/k*N),x,t(3),1)+k*(t(1)-t(2))/d*t(3)^(N-1);
end
And then I want to solve the eqaution system regarding some parameter combanation:
clc;
clear all;
syms x;
m=25;m1=20;N=1:20/m1:20;
t0=[5:50/m1:55;35:50/m1:85;1:0.5/m1:1.5]';
v1=10:50/m1:60;
d=18:100/m1:118;
k=0:1/m:1;
t1=zeros(m1,m);
t2=zeros(m1,m);
t3=zeros(m1,m);
F0=[0;0;0];
options=optimoptions( 'fsolve' , 'Display' , 'iter-detailed' , 'TolFun' , 1e-2, ...,
'MaxFunEvals' , 1e10 , 'MaxIter' , 500 ) ;
% the solution regarding K%
for j=1:m1
for i=1:m
F0=fsolve(@(t)answer(t,k(i),x,N(11),v1(j),d(j)),t0(j,:),options);
t1(j,i)=F0(1);
t2(j,i)=F0(2);
t3(j,i)=F0(3);
end
end
It is ok when running with j=1,2, but when the iteration goes to j=3 and i=17, something goes wrong with the following warning:
从 sym 转换为 double 时出现以下错误:
Unable to convert expression into double array.
error: answer (line 4)
F(2)=int(1/sqrt(t(1)^2+(2*d*(t(3)^N)/k*N)+2*d*(N-1)*x^N/k*N),x,t(3),1)-3*k*t(1)/2*v1+t(3)/t(1);
error: @(t)answer(t,k(i),x,N(11),v1(j),d(j))
error: trustnleqn (line 211)
F = feval(funfcn{3},reshape(xTrial,sizes.xShape),varargin{:});
error: fsolve (line 408)
trustnleqn(funfcn,x,verbosity,gradflag,options,defaultopt,f,JAC,...
Hope someone can help me!
1 comentario
KALYAN ACHARJYA
el 8 de Jul. de 2019
I didnot find any error.

Respuestas (1)
Walter Roberson
el 8 de Jul. de 2019
0 votos
int() can fail to converge. When that happens, it returns an int() expression that then cannot be converted to numeric using implicit double() .
You could switch to numeric integration, but that would probably fail.
You could put in a try/catch but you would have the question of what value you should substitute when there is no convergence.
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!