MATLAB: How to implement polyval in more than one dimension when the summation includes complex coefficients

MATLAB: How to implement polyval in more than one dimension when the summation includes complex coefficients

MATLABpolyvaltaylor summation

My problem involves the following double summation
where are complex coefficients, and are positive constants. I think that I can apply the PolyVal2D function written by Mark Mikofski. However, as my coefficients are complex, I don’t think the function will work with my code.
My first attempt involved truncating a double summation after computing a specified number of orders in the taylor expansion. In order to do this. I created the function below.
function val2 = test(unm)
Eps = 1e-6; Delta = 1e-4; Nx = 48; Nz = 32; N = 8; M = 8;
coeff = zeros(N+1,M+1);
u_approx = zeros(Nx,Nz+1);
for j=1:Nx
for ell=0:Nz
coeff(:,:) = unm(j,ell+1,:,:); % Returns a 2D array of dimension (N+1) x (M+1) of complex doubles
val2 = u_approx;
(My code for how I form is omitted. I could provide the values of if necessary, it is a 2D array of complex doubles of dimension )
The above function references the function taylor_sum2
function [tsum] = taylorsum_2(c,Eps,Delta,N,M)
% taylorsum - Sums a truncated Taylor series.

% Inputs:
% c - Taylor series coefficients: [c_00,...,c_0N] ... [c_M0,...,c_MN] which are a 2D array of complex doubles of dimension (N+1) x (M+1)
% Eps - Value at which to sum for N
% Delta - Value at which to sum for M
% N - Degree of truncated Taylor series
% M - Degree of truncated Taylor series
% Outputs:
% tsum - Taylor sum evaluated at Eps and Delta
tsum = polyVal2D(c,Eps,Delta,N,M);
which then references the code written in polyVal2D. At line 31 of polyVal2D, code is written to check the input arguments of the coeffcients. It appears that the coefficients must be real for this code to work (my own testing returned odd results when this restriction was removed – all of the coefficients returned are greater than !)
%% check input args
validateattributes(p,{'numeric'},{'2d','nonempty','real','finite'}, ...
validateattributes(x,{'numeric'},{'nonempty','real','finite'}, ...
validateattributes(y,{'numeric'},{'nonempty','real','finite'}, ...
assert(all(size(x)==size(y)),'polyVal2D:sizeMismatch', ...
'X and Y must be the same size.')
Through this analysis, I have the following questions:
  1. Does the above function ( polyVal2D) work with a 2D array of complex doubles for coefficients? I emailed the author since I was unsure about expected functionality. I’m not sure if I could adjust the code inside polyVal2D so that it will work with my 2D array of complex doubles.
  2. If that is the case, I think that my other option is shown inside the answers to this_question. The polyfit_n function was created to handle scenarios similar to mine. I don’t know how to implement it, so I have instead tried to implement the polyVal2D function.

Best Answer

  • Hi Matthew,
    unless I’m missing something,
    % make up some data
    M = 5;
    N = 6;
    c = rand(N,M)+i*rand(N,M);
    eps = .3;
    delt = .4;
    for n = 1:N
    for m = 1:M
    polyv(n,m) = c(n,m)*eps^n*delt^m;
    or in place of the for loops,create a vandermonde-like matrix
    [nval mval] = ndgrid(1:N,1:M);
    vander = eps.^nval.*delt.^mval
    polyv1 = c.*vander;
    polyv1 - polyv % should be tiny
    Your values of eps and delta are small enough that you can hardly see the effect, so they are a lot larger in this example.
  • Add a Comment

    Your email address will not be published. Required fields are marked *