R/polyadd.R

Defines functions polyadd

Documented in polyadd

##
##  p ol y a d d .R  Polynomial Addition
##


polyadd <- function(p, q){
    if ( (!is.vector(p, mode="numeric") && !is.vector(p, mode="complex")) ||
         (!is.vector(q, mode="numeric") && !is.vector(q, mode="complex")) )
        stop("Arguments 'p' and 'q' must be real or complex vectors.")

    lp <- length(p)
    lq <- length(q)

    if (lp >= lq) {
        r <- p + c(numeric(lp-lq), q)
    } else {
        r <- q + c(numeric(lq-lp), p)
    }

    lr <- length(r)
    while (r[1] == 0 && lr > 1) {
        r <- r[2:lr]
        lr <- lr - 1
    }
    return(r)
}

Try the pracma package in your browser

Any scripts or data that you put into this service are public.

pracma documentation built on Jan. 30, 2018, 3:01 a.m.