Learn R Programming

polyMatrix (version 0.2.5)

ch2pn: Converts a character class object to a polynomial class object

Description

Receives a character class object -- which looks like the print image of a polynomial object -- and returns a polynomial class object.

Usage

ch2pn(chv, symb = "x")

Arguments

chv

a character class object like the print image of a polynomial object

symb

the required symbol of input polynom string

Value

A polynomial class object or a list of polynomial objects.

Details

This technical subrutin converts a character object to a polynomial object. The "x" is the default symbol in the input string. The output is a polynomial or a list of polynomials, without any defined symbol. The default print.polynomial writes out the output by the symbol "x".

See Also

pn2ch, pprt

Examples

Run this code
# NOT RUN {
chx <- "1 + x + x^3 + 2 * x^4 - 4 * x^5 - 15 * x^16"
p <- ch2pn(chx, "x")
# "polynomial" (as in package: 'polynom')
class(p)
# 1 + x + x^3 + 2*x^4 - 4*x^5 - 15*x^16
p
# ditto <= 'x' is the default symbol
ch2pn(chx)

# the same polynom over 'z'
chz <- "1 + z + z^3 + 2 * z^4 - 4 * z^5 - 15 * z^16"
# == 1: the only "x" power in the input string
ch2pn(chz)
# 1 + x + x^3 + 2*x^4 - 4*x^5 - 15*x^16
ch2pn(chz, "z")

# the same print by polyMatrix::pprt() print utility
pprt(ch2pn(chz, "z"), "x")

# 1 + 5*x - 5*x^2 - 2*x^3 + x^5 + x^6 - x^7
ch2pn("-2 * x^3 - 5 * x^2 + x^5 + x^6 + 5 * x - x^7 + 1")
# 1
ch2pn("-2 * x^3 - 5 * x^2 + x^5 + x^6 + 5 * x - x^7 + 1", "z")

# 2
ch2pn(" 2")
# 0
ch2pn("z^3")
# z^4
ch2pn("z^3", "z")

# 0
ch2pn(" 3 * z ^ 2 + 5 * z^3")
# 4
ch2pn(" 4  + 5 * z^3")
# 6 + 5*x^3
ch2pn(" 6  + 5 * z^3", "z")

# a list of 'polynomial' class elements: [[1]] x  [[2]] 1 + x^2
ch2pn(c(" x ", " 1 + x^2 "))

# col.wise a "polyMdlist" "polyMatrix" class object
polyMgen.d(2, 2, rawData=ch2pn(c("1", "x^2", "x", "0")))

# symbole given for output
polyMgen.d(2, 2, rawData=ch2pn(c("1", "x^2", "x", "0")), symb="x")

# symbole given for input and output
polyMgen.d(2, 2, rawData=ch2pn(c("1", "x^2", "x", "0"),symb="x"), symb="x")

# clean up
# rm(chz, p, chx)
# }

Run the code above in your browser using DataLab