How to go from a symbolic expression to a vector in MATLAB -


i working on function generate polynomial interpolants given set of ordered pairs. input indexes of node points in 1 vector, , values of function interpolated in second vector. generate symbolic expression lagrange polynomial interpolates set of points. able go symbolic form vector form comparison test functions , such. is, have generates polynomial p(x) in terms of symbolic variable x. sample polynomial vector, , values polynomial on (for example) linspace(-1,1,1000). if possible, how do it?

i guess i'll include code have far:

function l_poly = lpoly(x,f) %   returns polynomial interpolant computed lagrange's formula syms n=size(x,2); l_poly_vec = 1; l_poly=0; k=1:n,     l=1:n,         if (k ~= l)             l_poly_vec=l_poly_vec*(a-x(l))/(x(k)-x(l));         end     end     l_poly=l_poly+f(k)*l_poly_vec;     l_poly_vec = 1; end 

i plan on adding third (or possibly fourth) input depending on how can solve issue. i'm guessing need length of vector want sample , endpoints.

if understand correctly, you've constructed lagrange interpolating polynomial using symbolic toolbox , wish evaluate on vector of values. 1 way use function sym2poly extract coefficients of symbolic polynomial, , use polyval evaluate it. alternatively, use matlabfunction convert symbolic expression regular matlab function; or use subs substitute in numeric value 'x'.

however, better off avoiding symbolic toolbox altogether , directly constructing coefficients of lagrange interpolating polynomial, or, better yet, use different interpolation scheme altogether. function interp1 might place start.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -