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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Translate the entire conversation x

Must be a factor

YA_10963798
14-Alexandrite

Must be a factor

Hi there

I have a problem with this function . The issue is R is a cumulative value so the R2=R0+R1> 

R3= R0+R1+R2 and so on... I wanted to implement that in this function but an error ( must be a vector ) shows 

Is there a way to fix this or to write it differently 

YA_10963798_0-1768299322575.png

Thanks 

The sheet is attached prime 11 

40 REPLIES 40
Werner_E
25-Diamond I
(To:YA_10963798)

There should be no difference between an explicit and an implicit (invisible) multiplication.

Implicit multiplication is called "scaling operator" by PTC and usually is used between a quantity and its unit, like in

Werner_E_0-1768996016128.png

which seems to be the reason why PTC has chosen Ctrl-Shift-U  for the keyboard short.

But its allowed to use that operator between two 'normal' variables or constants as well, as you did for some reason. Problem only may be that its harder to read and to distinguish between a single variable H2O4 and the product H2 O4..

There is one difference though and this is why we could use that scaling operator as some sort of postfix notation when calling a function: If the second operand is a function name, this function is applied to the first operand:

Werner_E_1-1768997006539.png

 

According your other problem I sure would need a worksheet to play with (preferably with small demo data and nice simple variable names) and this time it should clearly show the problem you experience. It's still the many NaN's, or is it something else?
It's necessary that you clearly state what the problem is! E.g. in your last post you wrote " the difference now my M,f1 and q are nested "  but the screenshot you showed below this statement did not use any f1 or q - that's confusing! f1 and q were seen in the screenshot above this statement but this seems to be working as expected.

 

YA_10963798
14-Alexandrite
(To:YA_10963798)

Hi Werner 

Thank you for the explanation . Now it is clearer in mind that the difference between the two dots doesn't mean dot product and vector product . 

 

For my problem . Yes f2 still all NaN unfortunately. 

in my original sheet this is the result 

 

YA_10963798_0-1768999032421.png

but I got M 

YA_10963798_1-1768999077054.png

I'm trying to do the same function in smaller sheet for you to use , but I got this 

YA_10963798_2-1768999208665.png

actually it is not important for me in this mock sheet because I have the results in the main sheet ... but I need to fix the step after to find f2 and write the correct iterator 

Can you help me with this ... would you just got any results for M and fix f2 ? 

Thanks 

Yusra 

Werner_E
25-Diamond I
(To:YA_10963798)

I feel like we're going around in circles! 😞
The sheet you just posted shows (again, or still) the already explained problem with the 1x3 matrix instead of the expected 3x1 matrix.

That should have been dealt with and sorted out long ago!

 


@YA_10963798 wrote:

Hi Werner 

Thank you for the explanation . Now it is clearer in mind that the difference between the two dots doesn't mean dot product and vector product . 

 


Both operators give you the vector dot product if applied to two vectors unless you explicitly vectorize the expression

Werner_E_0-1769003295101.png

 

The outer vector product (cross product) is a separate operator and accepts 3x1 vectors only

Werner_E_1-1769003368850.png

 

YA_10963798
14-Alexandrite
(To:Werner_E)

In my original sheet it is working I got M ... but yes there all matrix have the same dimensions . 

See I got M 

YA_10963798_0-1769004026782.png

 

I need to fix f2 only 

so even if you fix M anyway you prefer it is okay . I just need to fix the iterator in f2 function 

Do you want me to share the original sheet ? 

 

Werner_E
25-Diamond I
(To:YA_10963798)

Can't you create a simple  but correct demo sheet duplicating the problem.

I guess I will be much too confused by the many similar but different irritating variable names and the huge data of your original sheet.

I think its important to break down the problem to its basic cause and honestly I don't understand your "I need to fix f2 only" as i can't see any f2 anywhere and would not know what to fix.

 

BTW, in your original sheet - are you sure that the three elements of M.i.center are normal 1594x1 vectors containing just scalars and NaN's?

Try to display one of these vectors -> M.i.center[1=  and see what the result is. 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hi Werner 

I created a smaller version of the problem for this thread . 

 

I'm trying to get a nested results for (f2) which was a result of previous calculations of (f1 and M ) for three different situations of (q and sigma and R) 

in f2 function itself ( if you still remember their was a (i) and n) which were used to consider the layer of interest and n to calculate the layers above the layer of interest ) 

 

So f2 should be the result of three situations in each situation it consider the layer of interest and the  sum layers above

You showed me this > but that only for one situation 

YA_10963798_0-1769681564276.png

Then I asked about the loop in another thread and you showed me this ( I tried to use it in this function ) 

YA_10963798_1-1769681608708.png

Still I got NaN 

YA_10963798_2-1769681657292.png

I really need you help , the sheet is attached 

Thanks 

Werner_E
25-Diamond I
(To:YA_10963798)

Is it expected that the values in Re are all non-real?

They have to be because you take the log of negative values (values in sigma are negative)

Werner_E_0-1769702236307.png

 

Furthermore your fsingle is problematic because of two reasons.

1) its already written to deal with nested matrices M

2) it does not use the arguments gamma and sigma provided bit rather the worksheet variables with similar but different names (I really would wish you would use simpler variable names without subscipts).

So this is what your fsingle should look like:

Werner_E_1-1769703225526.png

 

I made a simple test with real simple test values for the arguments which are just similar to the first few values of the original vectors and also considering that dz has one element less than the other vectors as is the case with your original data.

I noticed that the size of the result is 1 element larger than the size of the inputs (is this as it should be?) and also that we get all NaN's excepts the first entry because this is forced to a zero in the program which starts with the calculation of R2.

Werner_E_4-1769704059237.png

It also was clear from this test that the non-real values in M are not the reason for the problem.

 

The problem with the all NaN's stems from vector sigma

Werner_E_2-1769703280794.png

Its first value with index 1 is a NaN and this value is used to calculate R2. That means that R2 results in a NaN. But R2 is used to calculate R3 and so R3 ends up being a NaN as well, And this goes on and on up to the last R. So all values must end up being NaN's.

The NaN in vector dz may have the same effect as well.

 

I have no idea why sigma and dz contain NaN's and what the calculation you do actually should achieve and how it should be related to the input values. So I can't help anymore to fix it.

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hi Werner , 

Thanks for replying 

Let's start from the last question you asked : 

>>I have no idea why sigma and dz contain NaN's and what the calculation you do actually should achieve and how it should be related to the input values. 

Sigma contain ( NaN) because in R calculation I need to divide (q/sigma) and sigma's first value was zero , so you advised me in the past to change the zero to NaN so I can get the results.

YA_10963798_0-1769759944261.png

 

>> Second comment >>

Its first value with index 1 is a NaN and this value is used to calculate R2. That means that R2 results in a NaN. But R2 is used to calculate R3 and so R3 ends up being a NaN as well, And this goes on and on up to the last R. So all values must end up being NaN's.>> 

So in this case I should rechange the NaN to zero ?? to get rid of the NaN in f 

 

 

>> Third comment

I noticed that the size of the result is 1 element larger than the size of the inputs (is this as it should be?)

I wanted to add the first layer ( imaginary layer)  so I made one but put all its values as zero 

 

>> Fourth 

Is it expected that the values in Re are all non-real?

They have to be because you take the log of negative values (values in sigma are negative)

 

This is my bad I will fix it 

 

>> For your last comment 

 So I can't help anymore to fix it. >> Thanks anyway you already helped me so much , I really appreciate all your responses

YA_10963798
14-Alexandrite
(To:Werner_E)

Werner 

I solved it ....> Thanks to your last reply about NaN 

YA_10963798_1-1769761859374.png

Thanks a lllllllllllllllllllllllllllllllllllllot 

 

Werner_E
25-Diamond I
(To:YA_10963798)

Great! Glad you found a suitable solution for your problem.

Yes, I remember that you had a calculation which failed for one value and so I suggested to trap that error via try...onerror.... But nonetheless we have to return some kind of value in that case. Returning a text string with an appropriate message usually is a bad idea because this is not treated as a number and so could make subsequent calculations fail (e.g. you can't assign a unit to a string). So whenever a calculation is applied to a series of values and it fails for one of them I usually assign a NaN as the result in that case because its treated as a number and I can easily check for NaN in any subsequent calculation. Of course this means that in subsequent calculations you always must be aware that a 'value' NaN could be present and you have to write your calculations in a way so they can deal with that.

But of course it depends on the use case which value to return in case of a failing operation If infinity or  1000 MV is more appropriate, than a NaN, then assign infinity or 1000 MV instead of NaN and if 0 Pa makes more sense then assign that.

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thank you so much . 

Announcements

Top Tags