Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a function only when needed 1

Status
Not open for further replies.

jcclaser

Industrial
Jan 29, 2010
1
Hi,

In a Mathcad program, I noticed that a function is recalculated while it does not need to be. Here is an example:

f(x):= x^2 + 1

g(x,y):= f(x) + y

y:= 0,1 .. 10

[graph of g(x,y) vs. y]

Normally, when y is varied, f(x) should not be recalculated, it should be calculated only for the first value of y. But I noticed that f(x) is calculated for each value of y.

Is there a way to force the program to calculate f(x) only once for all?

Thanks a lot,

JC

 
Replies continue below

Recommended for you

Would you do that by

i=0,1;10
g(f(x),i)=fx+y

?
 
I recently did a calculation and this function recalculation proved to be quite a bit of problem (calculations took e.g. 10-15mins, whereas the same calculation done as a Flash program was executed in a minute or two). The way I used to get around this problem was switching to using matrices instead of functions. The speed of calculations was greatly improved...

(Your example would be f[x:=x^2+1 and g[x,y:=f[x +y)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor