Worked Examples & Tips

On this page

Complete calculation scenarios, practical tips, and solutions to common issues.

Worked Examples #

Basic Calculations #

# Simple Math

5 + 3
10 - 2
4 * 5
20 / 4
2 ^ 3
10 % 3
Results
5 + 38
10 - 28
4 * 520
20 / 45
2 ^ 38
10 % 31

Variables #

# Budget

salary = $5000
bonus = $500
expenses = $3000

net = salary + bonus - expenses
Results
salary = $5000$5,000.00
bonus = $500$500.00
expenses = $3000$3,000.00
net = salary + bonus - expenses$2,500.00

Comparisons #

# Checks

salary = $50000
threshold = $60000

is_high_earner = salary > threshold
needs_raise = salary < $40000
meets_target = salary >= $50000
Results
salary = $50000$50K
threshold = $60000$60K
is_high_earner = salary > thresholdfalse
needs_raise = salary < $40000false
meets_target = salary >= $50000true

Complex Expressions #

# Mortgage

principal = $200000
rate = 0.04
years = 30
months = years * 12

monthly_rate = rate / 12
payment = principal * (monthly_rate * (1 + monthly_rate) ^ months) / ((1 + monthly_rate) ^ months - 1)
Results
principal = $200000$200K
rate = 0.040.04
years = 3030
months = years * 12360
monthly_rate = rate / 120.0033
payment = principal * (monthly_rate * (1 + monthly_rate) ^ months) / ((1 + monthly_rate) ^ months - 1)$954.83

System Sizing #

# Server Capacity Planning

peak_load = 50000 req/s
server_capacity = 2000 req/s
servers = peak_load at server_capacity per server with 25% buffer

# Storage
daily_data = 100 MB/s over 1 day
monthly_storage = daily_data * 30
disks = monthly_storage at 2 TB per disk
Results
peak_load = 50000 req/s50K req/s
server_capacity = 2000 req/s2K req/s
servers = peak_load at server_capacity per server with 25% buffer32 server
daily_data = 100 MB/s over 1 day8.24 TB
monthly_storage = daily_data * 30247 TB
disks = monthly_storage at 2 TB per disk124 disk

Mixed Markdown #

# My Monthly Budget

I earn a salary and get bonuses.

## Income

monthly_salary = $5000
annual_bonus = $3000
monthly_bonus = annual_bonus / 12

Total monthly income:
total_income = monthly_salary + monthly_bonus

## Expenses

- Rent: $1500
- Food: $600
- Utilities: $200

rent = $1500
food = $600
utilities = $200
total_expenses = rent + food + utilities

## Summary

Monthly surplus:
surplus = total_income - total_expenses

Can I save 20%?
savings_goal = total_income * 0.20
can_save = surplus >= savings_goal
Results
monthly_salary = $5000$5,000.00
annual_bonus = $3000$3,000.00
monthly_bonus = annual_bonus / 12$250.00
total_income = monthly_salary + monthly_bonus$5,250.00
rent = $1500$1,500.00
food = $600$600.00
utilities = $200$200.00
total_expenses = rent + food + utilities$2,300.00
surplus = total_income - total_expenses$2,950.00
savings_goal = total_income * 0.20$1,050.00
can_save = surplus >= savings_goaltrue

Tips #

Organize with Markdown #

Use headers and prose to structure your thinking:

# Q1 Budget

## Revenue Assumptions
monthly_revenue = $50000
q1_months = 3
total_revenue = monthly_revenue * q1_months

## Cost Breakdown
fixed_costs = $20000
variable_pct = 30%
variable_costs = total_revenue * variable_pct
Results
monthly_revenue = $50000$50K
q1_months = 33
total_revenue = monthly_revenue * q1_months$150K
fixed_costs = $20000$20K
variable_pct = 30%30%
variable_costs = total_revenue * variable_pct$45K

Use the Preview Pane #

Press Ctrl+P in the editor to toggle the preview pane, which shows evaluated results alongside your source.

Get Help on Functions #

Run cm help functions to see all available functions with descriptions and usage patterns. Run cm help constants for unit constants, or cm help frontmatter for frontmatter directives.

Troubleshooting #

“Undefined variable” #

Variables must be defined before use. Check that:

  1. The variable is spelled correctly
  2. It’s defined on an earlier line
  3. No typos in the name

“Incompatible units” #

You can’t add meters to kilograms. Check that operations make physical sense.

“Parse error” #

The line isn’t valid CalcMark syntax. Common issues:

  • Missing operator between values
  • Unclosed parentheses
  • Invalid characters