Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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
Thanks
The sheet is attached prime 11
Solved! Go to Solution.
Hi Werner
Is this value calculating the sum of the layers before?
Thanks
@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
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
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).
Thank you ... you are a legend
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...
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
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.
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.
Hmmm I understand your point . without the absolute to prevent the function from having negative values otherwise mistakes can occur
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:
and make this calculation (basically a recursion)
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):
Yes exactly this is why I used stack function for M
Thank you for pointing that out
I will try both and see
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
what if M is nested like this
How can I write a loop that go through all of these values without conflicting the values ...like calculate each column separately?
Thanks
You could rewrite f2 for a nested input M or (may better?) write a new function which calls the original f2 multiple times:
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
Like this you mean
@YA_10963798 wrote:
Like this you mean
The last R must be below and after (outside of) the for-loop!
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
I tried to do it like this as well but it doesn't work
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.
I attach the modified sheet, working from the last version I had
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 .
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
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" !?
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
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
Thanks
@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
or for equal size vectors containing scalars (dot product, not to mention the vector cross product)
or for matrices (of scalars!!) where the column number of the first matrix matches the row number of the second
or for scalars times a matrix (of scalars!!)
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.
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.
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
Or write a utility function which handles three factors
Ok But why if no error occurs , the results will be all (NAN)
What does that imply ?
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.
I used the last sheet you sent and I just changed the first value of M to NaN , then I all got f2 = NaN
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
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
