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

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 

ACCEPTED SOLUTION

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

Not sure if these are the values you need

Werner_E_0-1768305136148.png

 

View solution in original post

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

Not sure if these are the values you need

Werner_E_0-1768305136148.png

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hi Werner 

Is this value calculating the sum of the layers before?

YA_10963798_0-1768305456978.png

Thanks 

 

Werner_E
25-Diamond I
(To:YA_10963798)


@YA_10963798 wrote:

Hi Werner 

Is this value calculating the sum of the layers before?

I have no idea WHAT this expression calculates, but it definitely calculates a sum of products of values based on previous R-calculations. We are calculating Ri+1, so Ri already exists as long as we define R1 somewhere in front of the loop.

You original approach

Werner_E_0-1768306038136.png

would not have calculated any sum (apart from the fact that it tried to use value not even existing at the time of calculation). Mi and Ri are simple scalar values and so is their product. There is nothing to sum up.

It's like writing

Werner_E_1-1768306321941.png

There is nothing to sum up (would need vectors, not scalars) and Prime even throws an error in that case (I would have expected the result 12).

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thank you ... you are a legend 

Werner_E
25-Diamond I
(To:YA_10963798)

You'll have to check if the indices (i and i+1) of the vectors sigma', dz, gamma, etc. still are correct. Lacking experience in your field of work obviously I can't do so.

Maybe you manually calculate the necessary first few values the hard way and compare if they match Prime's results.

 

As you tried to make that calculation ORIGIN-independent, you may replace the n=1 in the sum by n=ORIGIN.

 

I also noticed that you used the absolute value (actually the norm) around the second factor in your calculation, while the picture to the right of if (which you seem to try to duplicate) does not show anything like that!? If I replace the norm by a normal pair of parentheses we get different results and some of them are also negative. Not sure if the norm was done on purpose...

Werner_E_0-1768377495954.png

 

YA_10963798
14-Alexandrite
(To:Werner_E)

I see your point ...put in my sheet the origin is also one not zero. Why such difference occur? 

 

You are correct I'm trying to duplicate the image to the right where ( i) is the layer of interest and (j) should be also the layer above the layer of interest. However the first layer has zero stress and I do have to include it in the calculation so I used ( i) as the layer above the layer of interest and (i+1) as the layer of interest. 

Now for ( R*M) they should be the sum of values of ( R.M) in the layers above the layer of interest. 

 

The end results of (f) should be between zero and one . I don't think having negative values is correct . 

 

But I didn't understand why writing n=1 is different than n=origin when the origin in the sheet is 1 

Werner_E
25-Diamond I
(To:YA_10963798)

n=1 is NOT different from n=ORIGIN because, as you noted yourself, you have set ORIGIN=1 in your sheet.

I just suggested to use ORIGIN instead of 1 because I saw that you used ORIGIN instead of 1 in other places as well so that the calculations should be independent on the actual setting of ORIGIN.

 

The difference in my screenshot is not because I replaced 1 by ORIGIN in the sum but rather because I omitted the norm(absolute value) you had around the second factor and replaced them by a pair of normal parentheses.

Werner_E_0-1768382413492.png

Werner_E_1-1768382792564.png

 

I just noticed that there is no absolute value or norm in the picture to the right of your calculation so I thought I'd mention that.

I can't comment on the correctness of the values, though.

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hmmm I understand your point . without the absolute to prevent the function from having negative values otherwise mistakes can occur 

Werner_E
25-Diamond I
(To:YA_10963798)

I modified the calculations to use range variables and don't use a program.

Maybe that way its easier for you to follow the calculations step by step and find the problem.

Basically you use these vectors:

 

Werner_E_0-1768386968517.png

and make this calculation (basically a recursion)

Werner_E_1-1768387056598.png

So you can compare the effect of the norm/absolute side by side.

 

Some things I noticed (and I am not sure if they have any meaning or are intended anyway):

  • You stack M on top of 0 to come up with the same number of elements in M as in sigma.
    But that way the vector M starts with two(!) zero values. Not sure if this was intended.
  • The first (zero) elements of vectors dz and gamma never are used in the calculations
  • The last element of vector sigma (3600 Pa) never is used.

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Yes exactly this is why I used stack function for M 

Thank you for pointing that out 

I will try both and see 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hi Werner , 

Can I ask one more extra question in this thread? 

This is what we wrote previously , but her M has only on column [1654X1]  and it works great 

YA_10963798_0-1768568423317.png

what if M is nested like this 

YA_10963798_1-1768568578744.png

How can I write a loop that go through all of these values without conflicting the values ...like calculate each column separately?

Thanks 

 

 

Werner_E
25-Diamond I
(To:YA_10963798)

You could rewrite f2 for a nested input M or (may better?) write a new function which calls the original f2 multiple times:

Werner_E_0-1768569178845.png

The result would be a nested vector similar to what your nested M looks like.

 

And here is the modified function f2 (cyclef2 not needed any more) which accepts a normal vector M (as before) but also a nested vector of vectors M.

EDIT: there was a line missing in the program.

 

Will post the corrected function in an answer below

YA_10963798
14-Alexandrite
(To:Werner_E)

Like this you mean 

YA_10963798_0-1768569581924.png

 

Werner_E
25-Diamond I
(To:YA_10963798)


@YA_10963798 wrote:

Like this you mean 

YA_10963798_0-1768569581924.png

 


The last R must be below and after (outside of)  the for-loop!

Werner_E_0-1768571145506.png

 

YA_10963798
14-Alexandrite
(To:Werner_E)

YA_10963798_0-1768571588246.png

 

Werner_E
25-Diamond I
(To:YA_10963798)

You would have to send the sheet with non-working demo data.

Where do you land when you trace back the error? (Menu "Calculation"-"Error Tracing")

 

EDIT: I guess the faulty second definition of f2 to the right of cyclef2 may be the cause. Rename it or disable it and see if it works using the original f2

YA_10963798
14-Alexandrite
(To:Werner_E)

I tried to do it like this as well but it doesn't work 

YA_10963798_1-1768570083917.png

 

Werner_E
25-Diamond I
(To:YA_10963798)

dz, sigma, gamma are NOT nested vectors, so you should not treat them as such.

Also the stacking of M0 in front of M has to be done for every vector inside the vector M and not for M itself.

 

Here is a proposal for a modified function f2 which does not need the cyclef2.

It works with a normal vector M as before but also with a nested vector M.

Note that I used variables M and MM and also R and RR ! The names do not matter, but they must be different.

Werner_E_0-1768572854052.png

 

I attach the modified sheet, working from the last version I had

 

 

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thank you Werner 

I guess I am always facing the same problem again and again . 

The error is either ( it must be scalars or vector ) I need to understand how to tackle this otherwise I will be asking for each function I write . 

YA_10963798_0-1768814602799.png

Can you help be to understand these two expressions ? I read the article that Stuard wrote but I don't understand how use it  to solve my errors 

 

Thanks 

Yusra 

Werner_E
25-Diamond I
(To:YA_10963798)

That question seems to be quite different from the previous follow-up question!?

???? And I have no idea which "two expressions" you are talking of or and which "article of Stuart" you are referring to ????

 

Guess you'll have to use a for-loop looping through all the three vectors in each of f1, f2 and q and also use vectorization when you multiply those vectors.

 

My crystal ball told me that you are looking for a result like in "try3" or "try4" and not the result in "try2" !?

Werner_E_1-1768818708010.png

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thank you Werner 

By the two expression I meant ( must by vector - must be scalar ) I always get such error

 

I use the first and the second forth methods  you suggested but I getting NAN for all the matrix 

YA_10963798_0-1768820369824.png

 

and also the loop seems not to be correct , because I'm getting 1654 for each column value where I should get only 3 rows each raw has 1654 values

YA_10963798_1-1768820601167.png

Thanks 

 

Werner_E
25-Diamond I
(To:YA_10963798)


@YA_10963798 wrote:

Thank you Werner 

By the two expression I meant ( must by vector - must be scalar ) I always get such error



The problem is that you heavily work using nested vectors.

 

When you write  f1*f2*q  you get an error because in Mathematics multiplication is only defined for scalars

Werner_E_0-1768820403010.png

or for equal size vectors containing scalars (dot product, not to mention the vector cross product)

Werner_E_1-1768820434043.png

or for matrices (of scalars!!) where the column number of the first matrix matches the row number of the second

Werner_E_2-1768820841100.png

or for scalars times a matrix (of scalars!!)

Werner_E_3-1768820922636.png

 

But multiplication is NOT defined for any other odd nested data structure like nested vectors.

As soon as Prime encounters a multiplication with a matrix and the elements of the matrix are not simple scalars, the corresponding error message is displayed.

Werner_E_4-1768821090720.png

As there is no "official" math definiton how such unicorns should be 'multiplied', you must tell Prime in detail what you want to be done with such a data structure.

@StuartBruff  would probably write a generic multiplication function here that recursively digs into the data structure until it encounters scalars and can then multiply them 🙂

And his version most likely would be more elegant than my quick attempt below and maybe would even work in Express.

Werner_E_0-1768822149950.png

 

Of course you could also use such a utility function in your case. 

As its written for just two factors you could do it that way

Werner_E_1-1768822502995.png

Or write a utility function which handles three factors

Werner_E_2-1768822553258.png

 

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Ok But why if no error occurs , the results will be all (NAN) 

YA_10963798_0-1768822090406.png

 

YA_10963798_1-1768822141799.png

What does that imply ? 

Werner_E
25-Diamond I
(To:YA_10963798)

Can't comment on the values (NaN) and resulting data structure without seeing your actual data.

Maybe you can set up a simplified demo sheet with smaller vectors (and simpler variable names 🙂 ) which still shows the problems you encounter.

YA_10963798
14-Alexandrite
(To:Werner_E)

I used the last sheet you sent and I just changed the first value of M to NaN , then I  all got f2 = NaN 

YA_10963798_1-1768823651312.png

YA_10963798_2-1768823683357.png

 

 

 

I guess because f1 has NaN , in my sheet I calculate f1  and q first and they have NaN in the first row 

and then I calculated f2 and M which they both have q in their functions .....but the results were all NaN 

YA_10963798_0-1768823588523.png

 

 

 

Werner_E
25-Diamond I
(To:YA_10963798)

Again, I can't comment on this without seeing the actual data and calcs you are doing.

All I can say that all four methods I had shown work OK even when the first element in each vector is a NaN

Werner_E_0-1768836248440.png

 

Announcements

Top Tags