Get Help

Turn on suggestions

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

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Define Piecewise Function from Input Table

Options

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

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

Showing results for

Highlighted

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

10-03-2018
03:12 AM

10-03-2018
03:12 AM

All,

I'm attempting to start what should be a simple geotechnical effective stress calculation. My first step is defining a soil unit weight profile as a function of depth (z) in an efficient and robust method. In the past, I've used "if statements" to control this however they are cumbersome and not very sophisticated. An example of what I've done in the past is shown on Page 2 of the attached worksheet.

On Page 1 I attempted using "vlookup", however I ran into numerical issues and precision errors due to TOL...ideally, I would like to end up with a function that is as simple as the "vlookup" approach, but with the precision of the function defined by the "if statement". Any suggestions would be appreciated...I've attempted "for loops" and "while loops" without any success.

Thanks in advance!

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

10-03-2018
06:07 AM

10-03-2018
06:07 AM

The lack of precision of "match", "lookup", etc. (especially when used with units) can be very annoying quite often.

I would suggest implementing your own specialized lookup function to do the job better.

12 REPLIES 12

Highlighted
##

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

10-03-2018
03:48 AM

10-03-2018
03:48 AM

Re: Define Piecewise Function from Input Table

Hi,

Look up linear interpolation in help. You can arrange a matrix of depths and values to interpolate.

For example here is one that changes from compass direction to polar plot direction. The tolerance is built in.

Highlighted
##

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

10-03-2018
07:47 AM

10-03-2018
07:47 AM

Re: Define Piecewise Function from Input Table

Wouldn't

be a simpler but equivalent solution to your compass problem?

Highlighted

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

10-03-2018
06:07 AM

10-03-2018
06:07 AM

The lack of precision of "match", "lookup", etc. (especially when used with units) can be very annoying quite often.

I would suggest implementing your own specialized lookup function to do the job better.

Highlighted
##

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

10-03-2018
10:06 AM

10-03-2018
10:06 AM

Re: Define Piecewise Function from Input Table

I can't demonstrate it because "linterp" is a "premium function", but this should do what you want:

Highlighted
##

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

10-03-2018
10:07 AM

10-03-2018
10:07 AM

Re: Define Piecewise Function from Input Table

Or, you look up the help info on VLOOKUP and find that there's a way around TOL dependency:

Success!

Luc

Highlighted
##

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

10-03-2018
11:19 AM

10-03-2018
11:19 AM

Re: Define Piecewise Function from Input Table

Nice idea and it even can be streamlined a little bit:

Drawback may be that it fails for input values greater or equal to 30 ft.

Highlighted
##

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

10-09-2018
10:37 PM

10-09-2018
10:37 PM

Re: Define Piecewise Function from Input Table

Thanks so much for the assistance on this. There were a lot of great solutions to this question, but implementing a *custom *look-up function seemed to be the most efficient method in defining my profile of soil properties as a function of depth.

Thanks again!

Highlighted
##

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

08-05-2019
09:02 PM

08-05-2019
09:02 PM

Re: Define Piecewise Function from Input Table

Does anybody here use "SMath Studio"? I'm trying to recreate this sheet using SMath, but can't seem to get the same lookup function to work out (see attached screenshot).

Highlighted
##

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

08-06-2019
01:53 AM

08-06-2019
01:53 AM

Re: Define Piecewise Function from Input Table

Attach the sheet... NOT just a picture.

Luc

Highlighted
##

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

08-06-2019
07:14 AM

08-06-2019
07:14 AM

Re: Define Piecewise Function from Input Table

There is no "else" (or "otherwise" in Mathcad) in my suggestion.

The for-loop simply looks for the correct index which is then used in the last line.

Instead of using a for-loop with break it would be a cleaner approach to use a while loop.

That means following the rule * "Use a for-loop only if the number of iterations is known"*, which I had ignored in favor of comfort 😉

I am not sure but I also think that there is no system variable "Origin" in SMath and vector indices always start with 1 which the routine would have to consider.

Highlighted
##

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

08-06-2019
08:04 AM

08-06-2019
08:04 AM

Re: Define Piecewise Function from Input Table

It was very long ago that I test drived SMath so I downloaded and installed it and gave it a try. Feels a bit uncomfortable at first and I was missing a comprehensive help. Had to use a search machine to find help for various topics. Especially demanding was to find out how to add a new line in a program without adding a new vertical line, too. Found no keyboard short but just a way to do it with the mouse 😞

I found no equivalent to Mathcad's "ORIGIN", so I assume indexing starts with 1 and you can't change that.

Also I found no way to get rid of the "else" branch, which is not needed in our example. You may put anything there, a zero would be just fine. I decided for "continue" as in our case that's exactly what happens.

I also include the "cleaner" version which uses a "while" loop.

BTW, I remember there was an installer package which also included the most important add-ons and settings, which made for a good start. At first glance I was not able to find anything like that now and installed the pure program alone (and missed a lot, of course).

While I am aware that this is not the SMath forum - two questions anyway:

Does anybody know if there are that kind of "all-inclusive" installation packages still available?

I also found that many menus are unusable because I use a notebook with a 4K display. Does anybody know if there is a fix for this. The pic below show what I am experiencing and talking about:

EDIT: I was not able to attach the SMath file directly as I experienced the "The contents of the attachment doesn't match its file type" error message. We know this problem very well as it took endless until this problem had been finally resolved for Mathcad files. So it was needed to zip the file.

Highlighted
##

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

08-06-2019
08:22 AM

08-06-2019
08:22 AM

Re: Define Piecewise Function from Input Table

OK, the lookup-functions that were presented here have no error check anyway but I thought that the "while" version should at least be as good as the "for" one, So I guess its a good idea to prevent the index going up to high: