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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Translate the entire conversation x

I'm having trouble with the "for" loop

pannus0
10-Marble

I'm having trouble with the "for" loop

Hi dear, I'm having trouble with the "for" loop when I create a function and try to graph a spectrum as a function of time.
I have MathCAD version 11. It worked in the old version, but in this latest version, it shows me an error message stating that the variable T is not defined.
Why is this happening?

pannus0_0-1761138052930.png

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:pannus0)


It worked in the old version, but in this latest version, it shows me an error message stating that the variable T is not defined.
Why is this happening?

 


What you did worked OK up to version 9 of Prime.

You are using an undocumented trick which turned a range into a vector - the inline evaluation (the = at the end) did the trick.

Werner_E_0-1761145158061.png

So up to Prime 9  variable T was now a vector, but starting with Prime 10 this variable still is just a range and that's the reason your sheet is failing.

As Alan already said  you have to define "T" as a vector and there are many ways you could do so.

The easiest way is to use the new function "vec" (it was introduced with Prime 11).

Simply replace your definition of "T" with   T:=vec(0s,0.01s,Tmax and your sheet should again be up and running.

 

But actually I wonder why you would go through the hassle of using vectors at all. You are using a math program, not just a spreadsheet like Excel. So there is no need to manipulate vectors - you could rather use functions to do the job - much more versatile:

Werner_E_2-1761146925167.png

 

 

 

View solution in original post

5 REPLIES 5
AlanStevens
19-Tanzanite
(To:pannus0)

You have constructed T as a range variable.  It needs to be a vector.

As I only have the Express version I've done your worksheet without the programming structure.  However, your loop should work ok if you make the change from range variable to vector.

 

Please upload your worksheet next time - not just an image.

 

Spectrum.png

Hi AlanStevens 

sorry for not responding sooner, as I was unwell, I have , I have some questions regarding the use of i:1...500, Ti:i/500*Tmax. Why did you use this method? Could you explain?
Thanks

Werner_E
25-Diamond I
(To:pannus0)

Its another way to create a vector T.

Note that Alan's sheet uses ORIGIN=0.

It seems from your picture that you are suing ORIGIN=1.

So to create the same vector T as you would using   T:=vec(0s,0.01s,Tmax)    you could use

Werner_E_0-1761767997182.png

or 

Werner_E_1-1761768049100.png

The "vec" function is not available in Prime 10 (and below) and furthermore its a 'Premium' function and so not available in the free Express version which was used by Alan.

Werner_E
25-Diamond I
(To:pannus0)


It worked in the old version, but in this latest version, it shows me an error message stating that the variable T is not defined.
Why is this happening?

 


What you did worked OK up to version 9 of Prime.

You are using an undocumented trick which turned a range into a vector - the inline evaluation (the = at the end) did the trick.

Werner_E_0-1761145158061.png

So up to Prime 9  variable T was now a vector, but starting with Prime 10 this variable still is just a range and that's the reason your sheet is failing.

As Alan already said  you have to define "T" as a vector and there are many ways you could do so.

The easiest way is to use the new function "vec" (it was introduced with Prime 11).

Simply replace your definition of "T" with   T:=vec(0s,0.01s,Tmax and your sheet should again be up and running.

 

But actually I wonder why you would go through the hassle of using vectors at all. You are using a math program, not just a spreadsheet like Excel. So there is no need to manipulate vectors - you could rather use functions to do the job - much more versatile:

Werner_E_2-1761146925167.png

 

 

 

Hi Werner_E,

sorry for not responding sooner, as I was unwell, but your answer was the most viable.

 
 
Announcements

Top Tags