cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

21-Topaz II

## Polynomial, yes or not?

Hello everyone,

I would like to create a Mathcad program that distinguishes whether the denominator of a given fraction is a polynomial or not, returning 0 or 1 for example. How do I do this?

Thank you.

14 REPLIES 14
23-Emerald III
(To:-MFra-)
Note sin (x) generally isn't viewed as a polynomial in x. But it can be written as such.

Luc
21-Topaz II
(To:LucMeekes)

Hi,

The function of the program should be something like this:

once the type has been identified, we pass to the transformation into a polynomial, if possible.

23-Emerald III
(To:-MFra-)

I got this far, so far:

I doubt whether this will (rather sure that this will not) work in Mathcad 15, but it does work in Mathcad 11.

Success!
Luc

21-Topaz II
(To:LucMeekes)

24-Ruby V
(To:-MFra-)

I am tempted to say that what you demand can't be done in Mathcad in a reasonable way as Mathcad does not provide the necessary tools.

Nonetheless here is a first attempt which may serve as a starting point for your own experiments.

There are a lot of drawbacks so far - you can only evaluate the function symbolically, its only working for functions in one variable and otherwise constants, ...

A few of the adverse effects could probably be corrected by some further investigations, but presumably not all. And I guess it will remain an uncertain, unreliable thing.

21-Topaz II
(To:Werner_E)

it would be better if the circled functions are not considered an error by mathcad. How to do?

23-Emerald III
(To:-MFra-)

I don't think there is a way.

You can switch off signalling of certain (types of) warnings.

You cannot switch off errors.

Luc

24-Ruby V
(To:-MFra-)

We could at least avoid the error(s) in "IsPoly2" by adding additional arguments and providing an alternative result in case the equality condition is not met. The value does not matter as we never arrive at the last line - if the equality condition is not met an error is thrown.

You may add two additional dummy arguments when you call "IsPoly2" from within "IsDenomPoly", but its not necessary to do so.

Not sure if we also could avoid the error in "IsDenomPoly" - in fact I don't understand the reason for the error message "This value must be a scalar".

23-Emerald III
(To:Werner_E)

Werner,

I'd expect an error message "This function needs more arguments." for your call of IsPoly2(v)  inside the function IsDenomPoly(f).

IsPoly2 requires 3 parameters, you call it with only 1...

Or have you found a way to define functions with optional parameters?

Luc

24-Ruby V
(To:LucMeekes)

@LucMeekes wrote:

Werner,

I'd expect an error message "This function needs more arguments." for your call of IsPoly2(v)  inside the function IsDenomPoly(f).

IsPoly2 requires 3 parameters, you call it with only 1...

Or have you found a way to define functions with optional parameters?

Luc

Using symbolic evaluations inside a function often give us strange result and effects and thats also the reason I wrote earlier that I consider this unreliable (maybe its just because I don't fully understand whats going on 😉

IsPoly2 in the original version (in the picture below: IsPoly1) returns either 1 if the argument is a polynomial or it throws an error (which I don't understand)!

So in IsDenomPoly I just distinguish between error or no error of the call to IsPoly.

The same would apply if I now would call IsPoly2 with two additional dummy arguments.

When called with just one argument (a polynomial) the result of IsPoly2 now is a function (of the two missing arguments), not 1. Thats normal behaviour if you call a function with less arguments than expected. As I don't need the return value 1 but just distuinguish between error or no fail.

BTW, I tried to implement IsPoly2 as a local function of either a generic IsPoly(f) or the specific IsDenomPoly(f)  to make it an all-in-one solution, but to no avail. It only worked if IsPoly2 is a separate function at worksheet level.

23-Emerald III
(To:Werner_E)

Regarding IsPoly itself:

You're assigning the result of that compound statement to the function aux(f), then assign aux(f) to v.

Apparently in Mathcad 15 it's possible to switch between a function with 1 argument and a function with none. (same as it is possible to supply 1 or 3 arguments to a function that's defined with just 1 argument)

Can you delete aux(f) altogether and assign that compound statement directly to v ?

If that's possible, you might also be able to delete the returning v from the compound statement, leaving just the assignment to v(x_) of the first line....

Luc

24-Ruby V
(To:LucMeekes)

Yes, you are right. In the final version we can omit the local function aux.

In an intermediate version where I used constants 1 and 2 instead of variables x and y we get wrong results without "aux". Guess this was the reason I experimented with that "aux" construction.

As to function calls with less arguments than necessary - here is how it works in Mathcad 15. Is it different in MC11?

I attach the sheet with the various steps in the development of the IsPoly function in MC11 format and also a pdf print so you can compare whats different in MC11.

23-Emerald III
(To:Werner_E)

Mathcad 11 does not have the local function feature (You cannot define a function within a program).

In addition (maybe: tied to that), it knows how many parameters a function needs, and enforces that.

Hence:

I think the check on number of parameters is generally a good thing, but it's in the way if you want to pull the kind of tricks we're trying.

Fortunately I was able to build an IsPoly function in Mathcad 11 (see my first reply in this thread); one that I think even works better, because it accepts (actually: needs) the name of the parameter of the polynome:

sin(x)*y+1 is a polynome in y, not in x.

Luc

24-Ruby V
(To:LucMeekes)

@LucMeekes wrote:

Fortunately I was able to build an IsPoly function in Mathcad 11 (see my first reply in this thread); one that I think even works better, because it accepts (actually: needs) the name of the parameter of the polynome:

sin(x)*y+1 is a polynome in y, not in x.

Luc

Unfortunately this function does not work in MC15 for various reasons. As far as I remember its possible to exchange variables for others in MC15, too (I used that in the past for a symbolic ODE solver for simple ODEs of first order), so possibly your routine could be repaired. Not sure, though, as the problem seems to be the loop you use to be able to manage vectors of expressions as well.

Announcements
Top Tags