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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Substitutes for Programming within Given Block?

ptc-4883573
1-Newbie

Substitutes for Programming within Given Block?

I am trying to use Given/Minerr to solve a system of equations with vectors as the unknown variables. The size of the vectors is controlled in the worksheet header, and is a user definable variable. Ideally, I would like to minimize the explicit equations in the Given block, and instead express them within a "for loop" with some sort of index or range variable (trivial example to follow). I am having trouble with this, as I am told that programming within the Given block is not allowed. Is there an alternative? Trivial Example: a_i={1,2,3}, b_i = {0,1,2} u_i={0,0,0} as an initial guess; the solution specified by one explicit equation::: Given u_i (Boolean-equal) a_i + b_i ;;;; uu=Minerr(u) should return uu_i={1,3,5}

Thanks for any advice!

8 REPLIES 8

I think we can do it not with range variables but with vectors.

xk.png

This should be no problem if a,b and u are vectors and not range variables. But you will have to use a, b and u and not a[i, etc.

Not sure if the following helps you with your problem. Maybe you consider posting a (preferably simplified) worksheet (you have to chose "extended editor" to do so). I am not sure where you would need programming inside the solve block which you would like to substitute - at least not by looking at your example.

Maybe the problem you have is, that you tried to use the individual vector elements by typing a[i rather than the vector itself inside the constraints in the solve block. Typing a[i gives you kind of a table consisting of the elements of the vector a. You can format that table so that it looks like a vector but it still will not be a real vector, so some operations on it will fail.

15.12.png

WE

I am trying to use Given/Minerr to solve a system of equations with vectors as the unknown variables. The size of the vectors is controlled in the worksheet header, and is a user definable variable. Ideally, I would like to minimize the explicit equations in the Given block, and instead express them within a "for loop" with some sort of index or range variable (trivial example to follow). I am having trouble with this, as I am told that programming within the Given block is not allowed. Is there an alternative? Trivial Example: a_i={1,2,3}, b_i = {0,1,2} u_i={0,0,0} as an initial guess; the solution specified by one explicit equation::: Given u_i (Boolean-equal) a_i + b_i ;;;; uu=Minerr(u) should return uu_i={1,3,5}

Thanks for any advice!

Thank you all very much for the responses. I think I still need to digest some of the subtler aspects of your answers. However, the primary issue I am having is that the equation system in my actual application does not have the same form for the entire range of variables. I need to parse-up the ranges of the vectors, some equations for some pieces, other expressions for other parts, etc. If there is some method of introducing index, range delimitation, or looping in the Given block, that would make things quite practical from a specification and maintenance aspect.

RichardJ
19-Tanzanite
(To:ptc-4883573)

Turn the solve block into a function. Then you can call the function with vectors, range variables, or in a program.

I believe the answer "Turn the solve block into a function", but I am having a little trouble, visualizing that advice. The attached file should show an example of what I am trying to do. Thank you for your time, sorry to cycle you folks.

example.gif

RichardJ
19-Tanzanite
(To:ptc-4883573)

Like this

Could the attached be of any help?

WE

16.12.png

Sorry, forgot an initial condition

16.12_2.png

Top Tags