Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Sep 04, 2019
07:25 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 04, 2019
07:25 AM

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.

Labels:

14 REPLIES 14

Sep 04, 2019
10:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 04, 2019
10:12 AM

Examples please.

Note sin (x) generally isn't viewed as a polynomial in x. But it can be written as such.

Luc

Note sin (x) generally isn't viewed as a polynomial in x. But it can be written as such.

Luc

Sep 04, 2019
01:30 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 04, 2019
01:30 PM

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.

Sep 04, 2019
05:56 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 04, 2019
05:56 PM

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

Sep 05, 2019
04:32 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
04:32 AM

Mathcad 15 returns this error:

Sep 04, 2019
07:33 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 04, 2019
07:33 PM

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.

Sep 05, 2019
04:35 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
04:35 AM

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

Sep 05, 2019
05:09 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
05:09 AM

I don't think there is a way.

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

You cannot switch off errors.

Luc

Sep 05, 2019
12:28 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
12:28 PM

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".

Sep 05, 2019
01:16 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
01:16 PM

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

Sep 05, 2019
05:25 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
05:25 PM

@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.

Sep 05, 2019
05:53 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
05:53 PM

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

Sep 05, 2019
07:24 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 05, 2019
07:24 PM

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.

Sep 06, 2019
02:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 06, 2019
02:15 AM

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

Sep 06, 2019
04:17 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Sep 06, 2019
04:17 AM

@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.