Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Tuesday, August 6, 2019

Using Calculated 1 Rep Maxes as an Index for Progression

I generally use an estimated 1 rep max as the measure of my progress in training for any particular exercise that I do. The FitNotes app somewhat encourages this thought process by providing a graph view that plots estimated 1 rep maxes over time. I don't disagree with the idea in principle. In fact, I had an idea that I might want to make a point of using 1 rep maxes as a method planning my progressive overload.

Progressive overload is the catch phrase that refers to adding additional training stimulus over time. From a given training stimulus, you can increase it a few ways, some of which lend themselves to different goals:
  1. Increase the weight
  2. Increase the repetitions per set
  3. Increase the number of sets
  4. Decrease the rest period
Doing any of these, or a combination of these, can increase the training stimulus so that you encourage additional growth. There's plenty to read out there about the difference between training for strength and training for muscle growth, but there may be a case to be made for balancing both of these goals. 

In very rough, non-technical terms: 
  1. Strength means your central nervous system is better at firing off more muscle fibers--maybe more intensely. Training for strength in this sense is normally done using lower repetitions per set.
  2. Muscle growth means the muscle fibers are bigger. They are usually able to move heavier weight than they used to as a result of being larger. Training for muscle growth is normally done using higher repetitions per set.
These are different strategies for training your muscles, and the divergence between them may or may not admit to synergies in their combination. Or, maybe it just doesn't suck too bad to mix it up a bit. I don't know. I'm not sure anybody really does. But I thought it would be interesting to use calculated 1 rep maxes as an index for the purpose of choosing a combination of weight and rep changes that results in a kind of theoretical progressive overload. I don't imagine I'm doing anything new, but hopefully, the spreadsheet I cooked up can make it easy enough for you to apply in your own training, if you don't think it's crazy.

Estimated 1 rep maxes are based on charts like this one: https://strengthlevel.com/one-rep-max-calculator. The idea is, if I do shoulder press with 95 lbs and I can do 12 reps before failure, I want to know how much weight I could do shoulder press with 1 time. According the chart I linked to, if I can do 12 reps with a given weight, that weight is 71% of my 1 rep max. So, if I divide 95 by 0.71, I am looking at my calculated 1 rep max. So, as long as you have a good chart of percentages, your calculation is pretty easy and is easily done in a spreadsheet using a look up or index function. I nabbed the percentages from my FitNotes app and am using them in my spreadsheet.

Reps % of 1 Rep Max
1 100
2 97
3 94.5
4 91.5
5 89
6 86
7 83.5
8 80.5
9 78
10 75
11 73
12 71.5
13 69.5
14 68
15 66.5

Using this chart on a sheet named '1 rep max percentages', I use the index function to drive a calculation. Along the left hand side I have the weight that is lifted and along the top I have the number of repetitions. To interpret the chart, look on the left hand side for the weight you lifted and find the column that corresponds to the number of repetitions you did. The number at that intersection is your estimated 1 rep max--provided the percentages driving the spreadsheet are legit. If you come across a chart you think is better, you can edit the values in that table and that will be reflected in the estimated 1 rep max.

Weight 1 2 3 4 5 6 7 8 9 10
2.5 2.50 2.58 2.65 2.73 2.81 2.91 2.99 3.11 3.21 3.33
5 5.00 5.15 5.29 5.46 5.62 5.81 5.99 6.21 6.41 6.67
7.5 7.50 7.73 7.94 8.20 8.43 8.72 8.98 9.32 9.62 10.00
10 10.00 10.31 10.58 10.93 11.24 11.63 11.98 12.42 12.82 13.33
12.5 12.50 12.89 13.23 13.66 14.04 14.53 14.97 15.53 16.03 16.67
15 15.00 15.46 15.87 16.39 16.85 17.44 17.96 18.63 19.23 20.00
17.5 17.50 18.04 18.52 19.13 19.66 20.35 20.96 21.74 22.44 23.33
20 20.00 20.62 21.16 21.86 22.47 23.26 23.95 24.84 25.64 26.67
22.5 22.50 23.20 23.81 24.59 25.28 26.16 26.95 27.95 28.85 30.00
25 25.00 25.77 26.46 27.32 28.09 29.07 29.94 31.06 32.05 33.33
27.5 27.50 28.35 29.10 30.05 30.90 31.98 32.93 34.16 35.26 36.67
30 30.00 30.93 31.75 32.79 33.71 34.88 35.93 37.27 38.46 40.00
35 35.00 36.08 37.04 38.25 39.33 40.70 41.92 43.48 44.87 46.67
40 40.00 41.24 42.33 43.72 44.94 46.51 47.90 49.69 51.28 53.33
45 45.00 46.39 47.62 49.18 50.56 52.33 53.89 55.90 57.69 60.00
50 50.00 51.55 52.91 54.64 56.18 58.14 59.88 62.11 64.10 66.67


The contents of cell B2 are =$A2 / (INDEX('1 rep max percentages'!$A$2:$B$16, B$1, 2)/100).  The index function takes three parameters:
  • Look up table: '1 rep max percentages'!$A$2:$B$16
  • Index (row) of table: B$1
  • Column of table: 2
The $ signs are a way of saying to Excel, "when you copy me to another cell, don't change me, keep me the same." So, the parts of the cell references that don't have a $ sign in front of them change when you copy them (relative copy), but the $ sign parts do not (absolute copy). The table of percentages is fixed with the $ signs and the row number (B$1) is fixed so that when you copy the cell down, it still looks to the first row for the number or reps. 2 is the column of the percentage table we need to feed into the formula. The table is pretty easy to make.

Here are links to the spreadsheet in Excel format and a print out to PDF, if you can't be bothered making the spreadsheet yourself.
Progressive Overload
Using the chart to help you with progressive overload is probably pretty obvious, but it maybe deserves some brief comments. Suppose you are doing an exercise with 155 lbs with 3 sets of 12 repetitions. 12 reps is not actually the most you can do in one set, but we don't care about your real 1 rep max. It's just an index. The fact that the index is used sometimes for calculating 1 rep maxes doesn't matter to us. It is just a way of guessing at a progression. We don't care that it isn't a "real 1 rep max", we only care that by interpreting this calculation as an index, we can use it to provide guidance for switching up our weight and reps at the same time.
It's just a number.
But it's a number that can help you.

Figure 1 shows some highlights of a way forward from 3 sets of 12 reps with 155 lbs to gradually move toward lower reps and higher weight while (hopefully) targeting an effectively greater stimulus. After you manage a full 3 sets of 12 reps, on your next workout after that, try for 3 sets of 10 with 165 lbs. In theory, if you achieve that, you have improved your strength (in some sense). If you don't succeed, you try again next work out, until you do succeed. Your next target could be 3 sets of 9 with 175 lbs. 

Fig 1. Highlights show a possible path of progression.
To the extent that this method of indexing the effective training stimulus may be valid, it can be used in a variety of ways. If you have been lifting very heavy, low reps, and you want to provide your tendons with a break or just change things up and lift light for fun, you can use this chart to help you decide what your target should be.

It's important to note though, that if you significantly change the number of reps per set, it will have a potentially large impact on your accumulated fatigue from set to set. My own experience suggests to me that with high repetition work, I accumulate a high amount of fatigue and with lower repetition work there is less of a fatigue angle involved. This confounds the matter when you make a large change to the number of reps and it probably comes apart at the seams a bit. These numbers may still help you get in the ball park.

Tuesday, October 9, 2012

How to make a .NET (Excel) Add-In Using Visual Basic Express 2010

Automation add-ins are easier than what follows and are the way to go if you just want a few custom functions.  Actually, for efficiency's sake, you might want to just use VBA functions added to Module1  (must be Module1—no renaming to a more suitable name) and then save the workbook as an Excel Add-In (*.xlam).  But, if it is user interaction or in some way making Excel "do stuff" (rather than just return a single result or an array of results), an add-in which implements the IDTExtensibility2 and IRibbonExtensibility interfaces may be a good strategy.  (The main alternative is to use VBA.)

Making an Excel Add-in in VB.NET involves the following (the ordering of the steps is not absolute):
  1. Ensure you have Office installed on the development machine and have the Primary Interop Assemblies (PIAs) installed in the Global Assembly Cache (GAC).  You can download them from Microsoft.  (The Microsoft installer will put the PIAs in the GAC.)
  2. Start a Class Library project in VB.NET.
  3. It's a good idea to generate your own strong name using the sn.exe tool (part of the .NET framework).  You only need one for multiple projects.  In a nutshell, you use the sn.exe tool to create a *.snk file which you will tell VB.NET about.
    • let VB.NET know where your *.snk file is by going to Project/Properties..., under Signing check "Sign the assembly" and choose a strong name key file.  You will be able to browse to where your *.snk file is
    • if your add-in is intended to be widely distributed, and especially if you want to sell your add-in, you would be well-advised to learn more about this topic to ensure your end-users don't get warning messages that cause them to be (perhaps unduly) alarmed.
  4. Apparently, step 4 is unnecessary, but I did step 4, so here it is:  In the project properties, go to Application and click the button Assembly Information....  In this screen, check the Make assembly COM-Visible box.
  5. Create a GUID.  There are several ways but a program called guidgen.exe may already be on your computer which will do the job.  Just search your computer for it.  It is located under C:\Program Files\Microsoft SDKs\Windows\... on my computer.
    • Copy and Paste the GUID into the Assembly Information... dialog box referred to in step 4.
  6. Encapsulate your project in a namespace either by typing it explicitly in the files or by specifying a root namespace in the project properties.
  7. Add references to needed PIAs, and extensibility (.NET tab)
    • It is recommended that you add these by referencing the Interop Assembly on the .NET tab, not the COM tab. You may need to browse for this: Look under C:\Windows\assembly\gac_msil\Microsoft.Office.Interop.Excel\...
  8. Create a class named Connect (seems that the name has to be Connect) which implements the IDTExtensibility2 and IRibbonExtensibility interfaces.
    • Implements Extensibility.IDTExtensibility2, Microsoft.Office.Core.IRibbonExtensibility
  9. Implement the methods of the interfaces.
  10. Decorate the class with COM visibility specifications and include functions for creating and deleting custom registry settings.
  11. Register your assembly with regasm.exe.
Steps 8, 9, and 10 are implemented in the following code snippet, which has been parameterized somewhat.


The functions RegisterFunction and UnregisterFunction are invoked by utilities like regasm.exe which comes with the .NET Framework.  I have created a batch file which I run in order to register the assembly.  You will need to modify it to suit your assembly.



Note that once the Add-in is registered and added, you will not need to reregister it after every Build (while developing).  

Saturday, August 11, 2012

DXFert: An Example VBA Add-In with Custom Ribbon

I implemented this project in Excel 2010. Only the Ribbon modifications are likely to be version dependent (unless you go way, way back). The form and macro in this project should work in any version of Excel.  

To use the macro launchmyForm(control as IRibbonControl)without the Ribbon buttons, such as you would need to do in an earlier version of Excel, you will need to either change

   launchmyForm(control As IRibbonControl) to launchmyForm() 

or 

write another macro that calls launchmyForm(someDummyObject).

In this post, I am going to walk through the building blocks of the project. Except for Excel, everything you need for this project is freely available for download.

What You Will Need to Develop Your Own Similar Project
  1. Excel 2007 or later.
  2. DXF file format documentation from AutoDesk
  3. CustomUI Editor Tool from Open XML Developer
  4. A program to allow you to test your DXF output (if that's what you're going for), such as DWG TrueView.
Overview

You need to 
  1. create a UserForm within a macro-enabled workbook (*.xlsm)
  2. write a one-liner macro that invokes the UserForm
  3. create a Ribbon interface which references the one-liner macro, and, finally,
  4. save the project as an Add-In (*.xlam) and activate it.
Creating the UserForm

If you don't have the developer tab available to you,...why ever not? Turn the silly thing on! To learn about developing user forms in Excel generally, there are lots of examples on the web, but I'll just give you a few key pieces of code that were important in my project.

Here's the code I used to open a file SaveAs dialog to help the user indicate the name and path for the file that the results will be exported:


This should work in very early versions of Excel all the way up to the present (version 2010) and probably future versions as well.  My main beef with it is there is a lack of control.  I would like it to complain about the selection of a file which already exists, but if I really wanted to I could include that complaint in my macro code right before I follow through with the export (which I didn't do—but you can, if you wish).

When you want to terminate the form (either by cancelling or after successful completion), you'll want use something like this:


You can learn a lot about the DXF format by looking at my code in the download.  (Hint:  If you have the Add-In added, you don't need to open up the file separately to see the code.  Just go to the Visual Basic Editor (button on the developer tab) and locate the user form DXFout_Form.  Right-click it and choose View Code.)  See page 143 of the AutoDesk's DXF format documentation for a description of the fields in the polyline Entity.

The one-liner code which the Ribbon will call is pretty easy:


The Ribbon expects to pass this control parameter to the subroutines it calls, whether you need to use the parameter or not.

Create the Ribbon Interface

I overcomplicated this my first few tries at it. Which is what a lot of people on the internet do. If you want your add-in to have its own ribbon elements, you create those elements using CustomUI Editor (referred to above) within a regular *.xlsm file. When you are ready to finalize it as an Add-In you just save it as an add-in and activate it. The same custom UI that showed up in the original *.xlsm file, will then show up all the time. No fuss, no muss. No Workbook_AddinInstall() code, no SetCustomUI(longComplicatedXMLString), no nothing, it just works! You do have to look at a bit of XML code, mind you.

But first, close down your *.xlsm file and open up CustomUI. Open up your *.xlsm file from within CustomUI. Go to the Insert menu and select Office 2010 Custom Part and, likewise, Office 2007 Custom Part. Now it is time for something ugly. Here is the xml code I used in my project:

For 2010 (customUI14):



For 2007 (customUI):



If you look at the <mso:button> tag you'll notice the launchMyForm bit.  That's the name of the procedure that is to be called.  One parameter is passed, namely, the a reference to the ribbon control that called the subroutine.

Save As an Add-In

At any point, you can turn your *.xlsm project into an Add-In.  (You can even continue editing it while it is an Add-In.)  Go to File, Save As, and select Excel Add-In from the file type options in the SaveAs dialog box.

Saturday, February 25, 2012

Best Fit Circle: find the center using Excel

Finding the center of a best fit circle depends on minimizing the same function we were concerned with in finding the radius, except that we are going to view it as a function of the center instead of as a function of the radius:

where a and b are the x- and y-coordinates, respectively, of the center and r is given by
What we have here is a function of two variables. It looks like three variables until you realize that r is calculated in terms of the other two. So, we can do a three dimensional plot and see what the scoop is. I used Maxima to do this and obtained a very good view of the surface near the best fit center of the points I have been using in all of my investigations of this problem. Here is the 3D plot of SSE(a,b):

What we are most encouraged to see in this graph is that it looks very smooth and it looks like there is exactly one point that is the lowest point. This lowest point is where the SSE function is minimized and constitutes the best center of the circle. (It might be that there are a few local minima somewhat close together that we could see if we zoomed up really tight to the bottom and we are probably happy with any of these as the "answer". Welcome to numerics.)

These formulae can be used in Excel. Designate two cells for each of the values a and b. You don't know what these are, but start with some guesses for these. You will reference these guesses in your Excel formulae. Put your points in consecutive rows after the pattern (x, y, se, R) where se references the x and y for that line as well as the values for a, b, and r. R will only reference x, y for that line and a, b from above. r above is the average of all the R values in the rows (don't include the 1/n in the R)--you may want to create a cell to contain this average and reference it in your se columns. Use absolute references for a, b, and r (if you have a cell for it) so you can copy and paste the formula easily. Make a sum formula at the bottom of your SSE column and it represents your SSE function as above. You want to use the Excel solver now. The SSE cell is the cell you tell it to minimize and the a and b cells you designate as the cells to be modified. The solver will tweak with the a and b values in an attempt to make SSE as small as possible. (The instructions about r and R might seem circular until you actually implement them. Follow through to the end and you'll see it really isn't circular.) Don't try too hard to follow the instructions--try to do the likely intent (as always).

For a Maxima approach see here.

Monday, February 6, 2012

The Polygon Worksheet

I have put together a worksheet in Excel to demonstrate a technique for calculating the vertices of a regular polygon.  You can download the worksheet here.

Overview

It demonstrates an application of vector rotation (and, by the way, complex number multiplication makes a good way to remember how to do vector rotation).  The motivating principle is to demonstrate how you can reduce calls to trigonometric functions while calculating vertices of a regular polygon.  Note that the spreadsheet does not give such (time) savings because it uses both methods: (1) direct calls to trig functions for each vertex in columns B and C and (2) vector rotation in columns E and F.  Also, the error of the vector rotation results is given in columns H and I.  You will notice that the error becomes larger as the vertex number increases.  The error occurs in the vector rotation method, not the trig function method (which is our control, since we believe these results represent the best approximation we can achieve using the floating point precision available in Excel).

The only values you should need to adjust are the number of sides cell, the radius cell, and the initial angle cell.  Everything else follows from these values.  A few notes are in order:
  1. The polygon that is determined, is inscribed inside of the circle with the given radius, and centered around the origin. 
  2. All angles are specified and calculated in radian measure.
  3. If fewer than 50 vertices are needed, the rows will repeat.
  4. If you wanted the center somewhere other than the origin, just apply a translation to the points.  So, if you want center (a, b), then each point P = (x, y), becomes P' = (x + a, y + b).  If you've made it this far into this post, you are probably more than capable.
Why Try to Reduce Calls to Trig Functions?

As the user of calculation software and scientific calculators, you may be wondering why we would want to reduce our use of trig functions.  The main reason would be for time-critical applications.  This particular spreadsheet is obviously not one of those, but it demonstrates the accuracy of the method.  So, how do I know that trigonometric functions take a long time to perform.  First of all, let me debunk some myths:
  1. Computers and calculators have tables of numbers in them that they use to determine values of "complicated" functions.  So wrong!  Computers and calculators compute/calculate these values!
  2. The calculations that computers and calculators do are just based on tables and interpolation.  This is rarely true.  Sometimes a programmer will use a method like this when he knows that the precision needs of his application will be met this way and will be much faster.  But it is actually more programming effort and would only be done when you didn't need very accurate results but you needed them really, really fast.
  3. Computers and calculators have hardware circuits that make the complex calculations almost as fast as the simple ones.  Not so.  Fact:  Multiplication is done with the fmult instruction.  Addition is done with the fadd instruction.  fmult takes way, way more computer cycles to compute than fadd.  fsincos takes way, way longer than fmult.  It is an unavoidable consequence of the nature of these calculations.
Recall that multiplication is dependant on addition.  Several additions actually.  So it should come as no surprise that by the time you put together a circuit that does the job that several additions and small multiplications can do, you end up with a circuit that takes longer to complete than one that just does addition.

The same is true of trig functions.  You know how you calculate them?  Here are the magic formulas:


The dots (...) indicate that it goes on and on and on and on and on, until the changes are small enough that you aren't changing the digits that mater to you. You may need more terms than are listed to get the accuracy you need. These formulas above are not written in the most computationally efficient manner, but you can rest assured that any circuitry or coding or combination thereof, which computes the values of the above functions will take longer than 4 multiplications and 2 addition/subtractions will (those are the operations involved in doing vector rotation).
Enter Vector Rotation

The key to how this method helps us, is that we can use a few trig function calls at the beginning and reuse the results several times over. We compute the direction vector for the central angle, θ, that each side covers. For a hexagon, this angle is 360°/6 = 60°, or π/3.
We need to determine the value of the central angle using direct calls to trig functions, but we will be able to reuse those values.  We also call trig functions to get our initial position.  From there we use our vector rotation method.  So, E14 and F14 use the values in E11 and F11 (renamed mx and my) and those of E13 and F13 to find their values:

E14 =E13*mx-F13*my
F14 =E13*my+F13*mx

Cells in rows below 14 do the same thing.  They still reference mx and my, which are the cosine and sine of our central angle, θ, respectively, and they reference the cells directly above them.  The concept for each row is:  rotate the point in the row above me around the origin by the central angle and tell me the x and y values for that rotated point.

Proof of the Formulas

Suppose we are given a point (x, y) and denote the distance from the origin as r and the angle it makes with the positive axis as i.  We wish to rotate (x, y) counter-clockwise about the origin by angle θ.  The diagram below illustrates:
Our new point (x', y') can be simplified:

                  
                      
                      
                 
                     
                     
If you look back at the formulas for E14 and F14, you may observe that mx and my correspond with sin θ and cos θ and E13 and F13 correspond with x and y.  That's all there is to it. 

Relationship with Complex Number Multiplication

If we represent the new point (x', y') as x' + y'j (where j is used to indicate the square root of -1), we can say:

This will produce an equivalent result to what we have above.