vpasolve - "The following error occurred converting from sym to double: DOUBLE cannot convert the input expression into a double array."
6 views (last 30 days)
Show older comments
Hello,
we use Chebyshev Polynomials to approximate a function (for our problem, it is not necessary to know the approximation by Chebyshev Polynomials). The approximation works well. Now we search for a specific y-value the respective x-value (which equals U(1)). For that we tried to use vpasolve. Our approach is working (see code below), but it takes a really long time. We guess it has something to do with the conversion from double to sym. We tried to convert everything to doubles, but then we received the following error message for the following line:
T(2, :) = z;
"The following error occurred converting from sym to double: DOUBLE cannot convert the input expression into a double array." We tried to convert all variables to double, but somehow it went wrong.
Does anybody know how to do the conversion from sym to double right in this case? Or is there in general a better way how we could solve our problem of getting the x-value for a specific y-value?
Thank you very much for any advice!!
This is the extract of the code which is running so far, but needs a very long time.
syms g
test = vpasolve(U(1) - chebEval1(coeffs, g, minWage,maxWage) == 0,g);
function val = chebEval1(coeffs,x,xMin,xMax)
% evaluate approximated function at x
% coeffs: column vector with coefficients
%
% inputs:
% coeffs ((n+1)x1 array)
% x (scalar) contains the x value at which the Chebyshev polynomial
% is evaluated.
% xMin (scalar) is the lower bound of the intervall (i.e. a in
% [a,b])
% xMax (scalar) is the upper bound of the intervall (i.e. b in
% [a,b])
%
% output:
% val (scalar) the y value.
N = size(coeffs, 1); % number of coefficients
z = (x-xMin).*2./(xMax-xMin) - 1; % z in range [-1, 1]
T = sym(zeros(N, 1));
T(1, :) = 1;
T(2, :) = z;
for i = 3:N
T(i, :) = 2.*z'.*T(i-1, :) - T(i-2, :);
end
val = vpa(T'*coeffs);
end
2 Comments
Walter Roberson
on 22 Jan 2020
That code cannot produce the error message you indicate. However, if you had
T = zeros(N, 1);
in the version you tested, then that code could potentially produce that error, if x or xMin or xMax were symbolic.
Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!