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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

redefining a range of variables, replotting the graph

AshehadAl
1-Visitor

redefining a range of variables, replotting the graph

Hi there,

I define a variable in mathcad as "i" that has a range of values, say i=0,1, 2 upto 28. Next, I compute a function, say f(i). I can easily plot f(i) versus i.

However, I don't know how to plot g(j) versus j, where j(i)= 0.1*i . Also the label of the x-axis should be now "j" not "j(i)" and the label of the y-axis should be "g(j)". Also, that at a given value of i, g(j)=f(i).

See the file attached. Any help would be greatly appreciated.

Thanks,

Ashehad

17 REPLIES 17

Something like the attached?

Mike

Thanks Mike. It works well and I can modify it too.

Cheers,

Ashehad

Thanks Mike.

No Problem.

All I changed was the Range Variable to a Vector Range. Just a matter of opinion, but I always try and keep away from Range Variables.

Mike

Further more, I modified "gg:=ff" to "gg(jj):=ff(ii)" so that I can find roots, if there is any. Using simple root function e.g root(gg(jj)-0.8,jj,0,2). I wish to locate the root. I know from simple mathematics that there is a root. But when I use "root(gg(jj)-0.8,jj,0,2)", certainly it can't locate.

Cheers,
Ashehad

I haven't used the root function much, so take my example with a pinch of salt.

Maybe other collabs will help who are more experienced.

Mike

Perhaps a little more like this.

Alan

Alan Stevens wrote:

Perhaps a little more like this.

Alan

Exactly like that.

Cheers

Mike

A range variable is not a set of values, like a vector. It is an iterator, like a loop in a program. This fact seems to confuse a lot of people, and leads to a lot of problems. So if you write root(gg(i)-0.8,i), where i is a range variable then Mathcad evaluates root(gg(i)-0.8,i) with i as the formal parameter for the function gg (in other words, it is NOT seeing the range variable "i"; it is a completely different i that is just a formal parameter). You did not give it the third and fourth arguments though, so it is not looking in a specific interval, but rather it is using the previously defined value of i as a guess. That's a range variable though, so it evalautes the root function for each guess value defined by the range (just as if you put it in a program loop with loop valriable i).

>A range variable is not a set of values, like a vector. It is an iterator, like a loop in a program< [Richard].

___________________________

Lovely definition ! The best in 10 years that should print in the mind of most new Mathcaders. In term of Mathsoft, a "scalar" that maintains the suite of the Mathcad functionality "scalar" at the kernel level, therefore immediately interpreted by the quick plot and that supports vectorizing [generally] ...etc.

Just a matter of opinion, but I always try and keep away from Range Variables

Good advice.

A good rule is to use range variables for indexing arrays, and nothing else. You will find that you break that rule fairly often, but if you try to stick to it then when you do use a range variable for something else it will be for a good reason.

Thanks everyone for a stimulative discussion. Attached, is another similar problem. Here, for a given range variable, say "i:0,1,2,3", we know it's function value i.e. we know a set of data corresponding to it.

I wonder in this case how can we vectorise the set of the data? Again we have "j(i):=0.1*(i)" and for a given "j" we have the same set of data as it was given originally. I wonder if we can denote it as somehow "g(j)".

See the attached file to follow the arguments.

Cheers,

Ashehad

wayne
12-Amethyst
(To:AshehadAl)

I am a simple man, and easily confused.

If you want to make a range variable dependent on another, just use j=0.1i; not j(i)=0.1i

Your function g(j)=f(i), dosn't work; j is the argument on the LHS, but you change to i on the RHS; the RHS must be a function of j, not i. When you

enter a value for j, Mathcad just substitutes that value for j on the RHS.

The root function works great, I do it all the time, but you need a continuous function, you have not defined a continuous function yet.

You can make a continuous function by fitting to the data using lininterp function, or one of the higher order functions, depending on what the data is.

Maybe the attached revisions will help.

Wayne

Richard Jackson wrote:

Just a matter of opinion, but I always try and keep away from Range Variables [Mike]

Good advice.

A good rule is to use range variables for indexing arrays, and nothing else. You will find that you break that rule fairly often, but if you try to stick to it then when you do use a range variable for something else it will be for a good reason. [Richard]

Same as always: it depends upon what are the next maths. If the next maths are "scalar" then keep it scalar [in your words range]. Often project are hybrid: scalar and vector and can be pursued in either mode to best suit the project.

i give u some example.

wayne
12-Amethyst
(To:AndyLee)

Andy,

you still have not defined a function, you have used a fuction to create an array, using the range variables.

If you type example(a,b)= you get a vector of numbers. In the plots, Mathcad is simply connecting points with

a straight line segment. You cannot use the root function, or any other functions meant to operate on a function,

on an array of points.

You could look at your example this way:

You generate a family of funcitons, one for each discrete value of a. b is then a variable, an you set the limits

(in the root function or on the graph) form 0 to 15. Now you can operate on each member of the family of curves.

You can operate on all familes of curves at the same time, for example,

root(a*cos(b),b,1,15)=

In your example, you will have 5 roots, so there might be a better function to find the roots.

Maybe the real problem you are working on would shed some light on what your are trying to accomplish,

maybe Jean knows, but I am still confused. If you have data, you need to fit a curve to the data to use the function

operators. The "linterp' function will produce the exact same curves as in your graphs, but you can operate on the

interp function like a continuous function in may ways, including numerical integration.

Wayne

>Maybe the real problem you are working on would shed some light on what your are trying to accomplish,

maybe Jean knows, but I am still confused.< [Wayne]

___________________________________

Can't be more right, Wayne: very confusing. That's the last ting I could think of, i.e: solving for a family of function. A family of single valued function will have one inverse only. That kind of project for an unknown function should be passed in the forum for a quick answer. It does not exclude the user to study and make it work as far as he can. In this example, we have 3 pairs of solutions for a unique Y. There is no limit in the number of Y's to be solved for, just a matter of indexing and run and extract appropriately.

>Further more, I modified "gg:=ff" to "gg(jj):=ff(ii)" so that I can find roots, if there is any. Using simple root function e.g root(gg(jj)-0.8,jj,0,2). I wish to locate the root. I know from simple mathematics that there is a root. But when I use "root(gg(jj)-0.8,jj,0,2)", certainly it can't locate. <
____________________
AFIU your root reference, solving for a function is the mathematical "InverseFunction". Some simple functions have an inverse , most don't have. Mathcad-Maple 11 and lower is very powerful in finding an "InverseFunction", in fact it can find about any. In some cases it leads to numerical instability, for which case we use the RootScanner instead. Here is the essential attached. What's red in this work sheet is normal red, i.e: not failure.
jmG

http://communities.ptc.com/message/152265#152265

Announcements

Top Tags