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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Mathcad 15 Getting Vectors From For Loops

AS_10102578
2-Explorer

Mathcad 15 Getting Vectors From For Loops

So I have a hw problem that doesn't need to be solved this way but I have a feeling I will be using the Modified bishops method on a future project so I wanna take my time on this. Basically, I have two equations :

AS_10102578_0-1635975008387.png

This is a function to find the Factor of Safety for a slope under certain conditions. In the actual psi equation, the F is The same FS in the upper eq. This requires an iterative process where you guess a F run it through psi and then the FS function. You then compare F to the resulting FS to see how close they are. You continue guessing F until F and FS converge to a similar number. The summations with the variable I represent the 7 different vertical slices that are being summed to form the whole slope. I want to write a program where I can input F as a sequence like 1,2 .. n. It then should pick the first F and run it through psi summing over the 7 slices. This should output one character into the psi resultant vector. Overall once it has run through all F, I want the resultant psi to be an nx1 vector with each psi value pertaining to each F. Then I want it to run the FS equation, similar to the psi I want this to sum over the seven slices for each psi input. At the end, I should have a resulting FS vector with one FS value for each F value input. Here is what I have so far:

AS_10102578_1-1635975796702.png

I am an absolute beginner with coding so any help would be greatly appreciated!

6 REPLIES 6

Hi,

Can you please include the sheet with the posting.

Cheers

Terry

 

Please attach your Mathcad worksheet to the message.

Hi,

We need to know the values of "l", "c", "w", "u", phi, and alpha to help you.

 

Cheers

Terry

Hi,

Set up a solve block that will iterate to a solution automatically.

Capture.JPG

StuartBruff
23-Emerald III
(To:AS_10102578)


@AS_10102578 wrote:

So I have a hw problem that doesn't need to be solved this way but I have a feeling I will be using the Modified bishops method on a future project so I wanna take my time on this. Basically, I have two equations :

AS_10102578_0-1635975008387.png

T At the end, I should have a resulting FS vector with one FS value for each F value input. Here is what I have so far:

AS_10102578_1-1635975796702.png


I don't have your version of Mathcad (I've only got Prime Express 7). However, I can make a few comments on the code you've shown.

 

You are expecting ψF to be a vector and use it as such in the 2nd expression for FS.  However, ψF doesn't exist as far as FS is concerned.  ψF is a local variable within the first FS expression and doesn't exist outside of it. So what you needed to have done was assign the result to variable ψF instead of FS - this ψF is a different object to the ψF defined within the first expression. 

 

A second problem you've got is that the ψF in the 1st expression is *not* a vector.  All the expression is doing is assigning the summation result to ψF., overwriting any previous values.  Consequently, the first FS simply has the value of ψF for F = 6.  You need a second iterator to assign the results to a new element in ψF  (you could use F, but only if any future F you have in mind continues to pull its values from an integer range).

 

The third problem is that you need an iterator (range variable or for/while loop) in the second expression to select each value of ψF; otherwise, you're just dividing the (intended) vector ψF into the top summation expression.

 

Unfortunately, my version of Mathcad doesn't allow programming, but I can show a (crude) version of your code that uses functions.

 

2021 11 04 A.png

 

Often, but not always, you can use vectorize operator to carry out parallel operations without using an iterator.  Occasionally, you can write an expression so that Mathcad automatically iterates over an expression. 

2021 11 04 B.png

 

Stuart

LucMeekes
23-Emerald III
(To:AS_10102578)

Apart from your iteration proposal and the solve block proposed elsewhere you can also do:

LucMeekes_1-1636038175732.png

If you equate this to FS, you get:

LucMeekes_2-1636038247227.png

So eventually:

LucMeekes_3-1636038283990.png

If you define:

LucMeekes_4-1636038321995.png

You can solve that simply with the Mathcad's built-in root() function:

LucMeekes_6-1636038500545.png

 

But of course only if the vectors l, u, w alpha, and the values phi and c are known.

 

Success!

Luc

 

P.S. Of course you could also define the function f as:

LucMeekes_0-1636043534390.png

but this function has a higher risk of running into errors because FS is the denominator of a ratio that fails if FS becomes 0.

 

Announcements

Top Tags