How Do You Calculate Equilibrium Price

How to Calculate Equilibrium Price: A Comprehensive Guide & Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 960px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } h1, h2, h3 { color: var(–primary-color); text-align: center; margin-bottom: 1.5em; } h1 { font-size: 2.5em; } h2 { font-size: 1.8em; margin-top: 1.5em; } h3 { font-size: 1.4em; margin-top: 1.2em; } .calculator-wrapper { background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 40px; } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { width: calc(100% – 22px); padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; display: block; } .input-group .error-message { color: #dc3545; font-size: 0.8em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { display: flex; justify-content: space-between; margin-top: 30px; gap: 10px; } button { padding: 12px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; } .btn-calculate { background-color: var(–primary-color); color: white; flex-grow: 1; } .btn-calculate:hover { background-color: #003366; } .btn-reset { background-color: #6c757d; color: white; } .btn-reset:hover { background-color: #5a6268; } .btn-copy { background-color: #ffc107; color: #212529; } .btn-copy:hover { background-color: #e0a800; } #results { margin-top: 30px; padding: 25px; background-color: var(–primary-color); color: white; border-radius: 8px; box-shadow: var(–shadow); text-align: center; } #results h3 { color: white; margin-bottom: 15px; } .result-item { margin-bottom: 15px; } .result-label { font-size: 1.1em; opacity: 0.8; } .result-value { font-size: 1.8em; font-weight: bold; display: block; margin-top: 5px; } .formula-explanation { font-size: 0.9em; color: #eee; margin-top: 20px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.2); } .intermediate-results { display: flex; justify-content: space-around; flex-wrap: wrap; margin-top: 25px; gap: 15px; } .intermediate-result-item { background-color: rgba(255, 255, 255, 0.15); padding: 15px; border-radius: 5px; text-align: center; flex: 1; min-width: 150px; } .intermediate-label { font-size: 0.95em; opacity: 0.8; } .intermediate-value { font-size: 1.3em; font-weight: bold; display: block; margin-top: 5px; } .chart-container { margin-top: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); text-align: center; } canvas { max-width: 100%; height: auto; } .chart-caption { font-size: 0.9em; color: #666; margin-top: 10px; } .table-container { margin-top: 40px; overflow-x: auto; } table { width: 100%; border-collapse: collapse; margin-bottom: 20px; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #f2f2f2; } tbody tr:hover { background-color: #e9ecef; } .table-caption { font-size: 0.9em; color: #666; margin-bottom: 10px; text-align: center; display: block; } .article-content { margin-top: 40px; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); text-align: left; } .article-content p, .article-content ul, .article-content ol { margin-bottom: 1.5em; } .article-content li { margin-bottom: 0.8em; } .article-content a { color: var(–primary-color); text-decoration: none; } .article-content a:hover { text-decoration: underline; } .faq-item { margin-bottom: 1.5em; padding-bottom: 1em; border-bottom: 1px dashed var(–border-color); } .faq-item:last-child { border-bottom: none; } .faq-question { font-weight: bold; color: var(–primary-color); margin-bottom: 0.5em; cursor: pointer; } .faq-answer { font-size: 0.95em; color: #555; } .related-links ul { list-style: none; padding: 0; } .related-links li { margin-bottom: 1em; } .related-links a { font-weight: bold; } .related-links span { font-size: 0.9em; color: #666; display: block; margin-top: 3px; } .highlighted-result { font-size: 2.5em; font-weight: bold; color: var(–success-color); display: block; margin-top: 10px; } .copy-feedback { font-size: 0.8em; color: var(–success-color); margin-top: 10px; display: none; }

How to Calculate Equilibrium Price

Understand the market's sweet spot where supply meets demand with our interactive calculator and guide.

Equilibrium Price Calculator

Enter the quantity consumers are willing to buy at a specific price (P1).
Enter the first price point (P1).
Enter the quantity consumers are willing to buy at a second, higher price (P2).
Enter the second price point (P2), typically higher than P1.
Enter the quantity producers are willing to sell at a specific price (P3).
Enter the first price point (P3).
Enter the quantity producers are willing to sell at a second, higher price (P4).
Enter the second price point (P4), typically higher than P3.

Market Equilibrium

Equilibrium Price (Pe)
Equilibrium Quantity (Qe)
Demand Slope (Md)
Demand Intercept (Bd)
Supply Slope (Ms)
Supply Intercept (Bs)
The equilibrium price (Pe) and quantity (Qe) are found where the demand and supply curves intersect. This calculator uses two points for each curve to determine their linear equations (Q = mP + b) and then solves for P and Q where Demand Quantity = Supply Quantity.

Demand Equation: Qd = Md * P + Bd
Supply Equation: Qs = Ms * P + Bs
At Equilibrium: Qd = Qs => Md * Pe + Bd = Ms * Pe + Bs
Solving for Pe: Pe = (Bs – Bd) / (Md – Ms)
Solving for Qe: Qe = Md * Pe + Bd (or Ms * Pe + Bs)
Results copied to clipboard!

Demand and Supply Curves

Visual representation of demand and supply curves and their intersection at equilibrium.
Input Data Points
Curve Type Point 1 (P, Q) Point 2 (P, Q)
Demand
Supply

What is Equilibrium Price?

Equilibrium price, often referred to as the "market-clearing price," is a fundamental concept in economics that describes the price at which the quantity of a good or service that buyers are willing and able to purchase (quantity demanded) exactly matches the quantity that sellers are willing and able to offer for sale (quantity supplied). At this specific price, there is no inherent tendency for the price to change because the market is in balance. The forces of supply and demand are in equilibrium, meaning neither a surplus nor a shortage exists.

Understanding how to calculate equilibrium price is crucial for businesses, policymakers, and consumers alike. For businesses, it helps in strategic pricing decisions, production planning, and forecasting sales. Policymakers use this concept to analyze the potential impact of taxes, subsidies, price controls, and other interventions on market outcomes. Consumers benefit from understanding how market prices are determined, which can influence their purchasing decisions and overall economic well-being.

Who should use it? Anyone involved in markets, from individual consumers and producers to large corporations and government agencies, can benefit from understanding equilibrium price. Economists, financial analysts, business managers, marketing professionals, and students of economics are primary users. It's also relevant for understanding broader economic trends and the functioning of various industries.

Common misconceptions about equilibrium price include the belief that it's a static, fixed point. In reality, equilibrium is dynamic and constantly shifts as underlying supply and demand conditions change. Another misconception is that the equilibrium price is always "fair" or "just." While it represents a market consensus, it can still result in prices that are unaffordable for some consumers or unprofitable for some producers, especially in markets with significant externalities or information asymmetry.

Equilibrium Price Formula and Mathematical Explanation

The equilibrium price (Pe) and equilibrium quantity (Qe) occur at the intersection of the demand curve and the supply curve. To calculate these values, we typically represent the demand and supply relationships as functions of price. For simplicity, we often assume linear demand and supply curves, which can be expressed in the form:

Demand Function: Qd = a – bP

Supply Function: Qs = c + dP

Where:

  • Qd is the quantity demanded
  • Qs is the quantity supplied
  • P is the price
  • 'a' is the demand intercept (quantity demanded when price is zero)
  • 'b' is the slope of the demand curve (change in quantity demanded per unit change in price)
  • 'c' is the supply intercept (quantity supplied when price is zero)
  • 'd' is the slope of the supply curve (change in quantity supplied per unit change in price)

At equilibrium, the quantity demanded equals the quantity supplied (Qd = Qs). Therefore, we set the two equations equal to each other:

a – bP = c + dP

To solve for the equilibrium price (Pe), we rearrange the equation:

a – c = bP + dP

a – c = P(b + d)

Equilibrium Price (Pe) = (a – c) / (b + d)

Once the equilibrium price (Pe) is found, we can substitute it back into either the demand or supply equation to find the equilibrium quantity (Qe).

Using the demand equation: Equilibrium Quantity (Qe) = a – b * Pe

Or using the supply equation: Equilibrium Quantity (Qe) = c + d * Pe

Our calculator uses a slightly different approach, deriving the linear equations from two data points for both demand and supply. Given two points (P1, Q1) and (P2, Q2) for a curve, the slope (m) is calculated as (Q2 – Q1) / (P2 – P1), and the intercept (b) can be found using the point-slope form: Q – Q1 = m(P – P1), which rearranges to Q = mP + (Q1 – mP1). The intercept is then (Q1 – mP1).

Variables Table:

Variable Meaning Unit Typical Range
Qd Quantity Demanded Units (e.g., items, kg, liters) Non-negative
Qs Quantity Supplied Units (e.g., items, kg, liters) Non-negative
P Price Currency (e.g., $, €, £) Non-negative
Pe Equilibrium Price Currency (e.g., $, €, £) Non-negative
Qe Equilibrium Quantity Units (e.g., items, kg, liters) Non-negative
Md Demand Slope (Change in Qd / Change in P) Units / Currency Typically negative for normal goods
Bd Demand Intercept (Qd when P=0) Units Can be positive or zero
Ms Supply Slope (Change in Qs / Change in P) Units / Currency Typically positive
Bs Supply Intercept (Qs when P=0) Units Can be zero or positive

Practical Examples (Real-World Use Cases)

Understanding how to calculate equilibrium price is vital in various economic scenarios. Here are a couple of practical examples:

Example 1: The Local Coffee Market

Consider the market for a popular brand of coffee beans in a small town. Market researchers have gathered the following data:

  • Demand Data: At $10 per pound, consumers demand 1000 pounds. At $12 per pound, they demand 800 pounds.
  • Supply Data: At $8 per pound, producers supply 700 pounds. At $10 per pound, they supply 900 pounds.

Calculation Steps:

  1. Calculate Demand Slope (Md): (800 – 1000) / ($12 – $10) = -200 / $2 = -100 pounds per dollar.
  2. Calculate Demand Intercept (Bd): Using point ($10, 1000): 1000 = -100 * $10 + Bd => Bd = 1000 + 1000 = 2000. Demand Equation: Qd = 2000 – 100P.
  3. Calculate Supply Slope (Ms): (900 – 700) / ($10 – $8) = 200 / $2 = 100 pounds per dollar.
  4. Calculate Supply Intercept (Bs): Using point ($8, 700): 700 = 100 * $8 + Bs => Bs = 700 – 800 = -100. Supply Equation: Qs = -100 + 100P.
  5. Find Equilibrium Price (Pe): Set Qd = Qs => 2000 – 100Pe = -100 + 100Pe => 2100 = 200Pe => Pe = 2100 / 200 = $10.50.
  6. Find Equilibrium Quantity (Qe): Using demand equation: Qe = 2000 – 100 * $10.50 = 2000 – 1050 = 950 pounds.

Result: The equilibrium price for coffee beans is $10.50 per pound, and the equilibrium quantity is 950 pounds. At this price, the amount of coffee consumers want to buy perfectly matches the amount producers want to sell.

Example 2: The Smartphone Market

A tech company is launching a new smartphone model. They estimate demand and supply based on different price points:

  • Demand Data: At $500, demand is 50,000 units. At $450, demand is 60,000 units.
  • Supply Data: At $400, supply is 40,000 units. At $450, supply is 50,000 units.

Calculation Steps:

  1. Calculate Demand Slope (Md): (60,000 – 50,000) / ($450 – $500) = 10,000 / -$50 = -200 units per dollar.
  2. Calculate Demand Intercept (Bd): Using point ($500, 50,000): 50,000 = -200 * $500 + Bd => Bd = 50,000 + 100,000 = 150,000. Demand Equation: Qd = 150,000 – 200P.
  3. Calculate Supply Slope (Ms): (50,000 – 40,000) / ($450 – $400) = 10,000 / $50 = 200 units per dollar.
  4. Calculate Supply Intercept (Bs): Using point ($400, 40,000): 40,000 = 200 * $400 + Bs => Bs = 40,000 – 80,000 = -40,000. Supply Equation: Qs = -40,000 + 200P.
  5. Find Equilibrium Price (Pe): Set Qd = Qs => 150,000 – 200Pe = -40,000 + 200Pe => 190,000 = 400Pe => Pe = 190,000 / 400 = $475.
  6. Find Equilibrium Quantity (Qe): Using supply equation: Qe = -40,000 + 200 * $475 = -40,000 + 95,000 = 55,000 units.

Result: The equilibrium price for the new smartphone is $475, and the equilibrium quantity is 55,000 units. This price point ensures that the number of smartphones consumers wish to buy aligns with the number the company plans to produce and sell.

How to Use This Equilibrium Price Calculator

Our Equilibrium Price Calculator is designed to be intuitive and provide quick insights into market dynamics. Follow these simple steps:

  1. Input Demand Data: Enter two price-quantity pairs for demand. For example, "Quantity Demanded at Price P1" and "Price P1", followed by "Quantity Demanded at Price P2" and "Price P2". Ensure P2 is different from P1 to calculate a meaningful slope. Typically, demand quantity decreases as price increases.
  2. Input Supply Data: Similarly, enter two price-quantity pairs for supply. For example, "Quantity Supplied at Price P3" and "Price P3", followed by "Quantity Supplied at Price P4" and "Price P4". Ensure P4 is different from P3. Typically, supply quantity increases as price increases.
  3. Click 'Calculate Equilibrium': Once all fields are populated with valid numbers, click the button.
  4. Review Results: The calculator will display the calculated Equilibrium Price (Pe) and Equilibrium Quantity (Qe). It also shows the derived slopes and intercepts for both demand and supply curves, along with a visual representation in the chart and a summary table of your inputs.
  5. Interpret the Results: The Equilibrium Price is the market-clearing price. The Equilibrium Quantity is the amount of the good or service that will be transacted at that price.
  6. Use 'Reset': If you need to start over or clear the fields, click the 'Reset' button. It will restore default values.
  7. Use 'Copy Results': To save or share the calculated values and key assumptions, click 'Copy Results'. The main result, intermediate values, and input assumptions will be copied to your clipboard.

Decision-Making Guidance: Businesses can use the equilibrium price as a target for their pricing strategies. If the current market price is above equilibrium, expect surpluses and potential price drops. If it's below, expect shortages and potential price increases. Understanding these dynamics helps in inventory management, production adjustments, and competitive analysis.

Key Factors That Affect Equilibrium Price

The equilibrium price is not static; it's a moving target influenced by numerous factors that shift the underlying demand and supply curves. Here are some key factors:

  1. Consumer Income: For normal goods, an increase in consumer income shifts the demand curve to the right (increasing equilibrium price and quantity). For inferior goods, demand decreases as income rises, shifting the curve left.
  2. Prices of Related Goods:
    • Substitutes: If the price of a substitute good (e.g., butter vs. margarine) increases, demand for the original good rises, shifting the demand curve right, increasing equilibrium price.
    • Complements: If the price of a complementary good (e.g., printers and ink cartridges) increases, demand for the original good falls, shifting the demand curve left, decreasing equilibrium price.
  3. Consumer Tastes and Preferences: Changes in fashion, trends, or perceived value (e.g., health consciousness) can significantly shift demand. A surge in popularity increases demand, raising equilibrium price.
  4. Technology and Production Costs: Advances in technology often lower production costs, shifting the supply curve to the right (decreasing equilibrium price and increasing quantity). Conversely, rising input costs (labor, raw materials) shift supply left, increasing equilibrium price.
  5. Number of Buyers and Sellers: An increase in the number of consumers in the market shifts demand right, raising equilibrium price. An increase in the number of producers shifts supply right, lowering equilibrium price.
  6. Expectations about Future Prices: If consumers expect prices to rise significantly in the future, they may increase current demand (shifting demand right). If producers expect prices to rise, they might decrease current supply (shifting supply left), both leading to a higher current equilibrium price.
  7. Government Policies (Taxes, Subsidies, Regulations): Taxes on producers increase costs, shifting supply left and raising equilibrium price. Subsidies lower costs, shifting supply right and lowering equilibrium price. Price controls (ceilings or floors) can prevent the market from reaching its natural equilibrium.
  8. External Shocks: Unforeseen events like natural disasters, pandemics, or geopolitical conflicts can disrupt supply chains, impact production, and alter consumer behavior, leading to significant shifts in both supply and demand, and thus affecting equilibrium price.

Frequently Asked Questions (FAQ)

What is the difference between equilibrium price and market price?
The market price is the price at which a good or service is currently being bought and sold. The equilibrium price is the theoretical price where quantity demanded equals quantity supplied. The market price tends to move towards the equilibrium price over time, but it may not always be exactly at equilibrium due to constant shifts in market conditions.
Can equilibrium price be negative?
In most practical economic scenarios, equilibrium price cannot be negative. Price represents the value exchanged for a good or service, and it's typically non-negative. A negative price would imply that sellers pay buyers to take the product, which is highly unusual outside of specific waste disposal or complex financial derivatives contexts. Our calculator assumes non-negative prices.
What happens if the price is above equilibrium?
If the market price is above the equilibrium price, the quantity supplied will exceed the quantity demanded. This results in a surplus (excess supply). Sellers will likely lower their prices to sell off excess inventory, pushing the market price down towards equilibrium.
What happens if the price is below equilibrium?
If the market price is below the equilibrium price, the quantity demanded will exceed the quantity supplied. This leads to a shortage (excess demand). Buyers will compete for the limited goods, potentially bidding up the price, or sellers will realize they can charge more, pushing the market price up towards equilibrium.
Does equilibrium mean the market is "perfect"?
No. Equilibrium simply means the market is balanced at a specific price and quantity, given current supply and demand conditions. It does not imply perfect competition, perfect information, or fairness. Markets can reach equilibrium even with monopolies, externalities, or significant information gaps.
How do taxes affect equilibrium price?
Taxes typically increase the cost of production or the price paid by consumers. This shifts the supply curve upwards (or to the left) and/or the demand curve downwards (or to the left). The result is usually a higher equilibrium price paid by consumers and a lower equilibrium price received by producers (after tax), with a lower equilibrium quantity traded overall.
Can the calculator handle non-linear demand or supply curves?
This specific calculator assumes linear demand and supply curves, as it calculates the equilibrium based on two points for each curve, effectively defining straight lines. Real-world demand and supply can be non-linear, requiring more complex mathematical models (calculus, integration) to find the precise equilibrium point.
What does a steep vs. flat slope mean for equilibrium?
A steep slope (high absolute value) indicates that quantity is very sensitive to price changes (elastic). A flat slope (low absolute value) indicates quantity is less sensitive to price changes (inelastic). The relative slopes of the demand and supply curves significantly influence how much the equilibrium price and quantity change when either curve shifts. For example, if demand is very inelastic (steep), a shift in supply will cause a large price change but a small quantity change.

© 2023 Your Financial Hub. All rights reserved.

var demandQuantityInput = document.getElementById('demandQuantity'); var price1Input = document.getElementById('price1'); var demandQuantity2Input = document.getElementById('demandQuantity2'); var price2Input = document.getElementById('price2'); var supplyQuantityInput = document.getElementById('supplyQuantity'); var price3Input = document.getElementById('price3'); var supplyQuantity2Input = document.getElementById('supplyQuantity2'); var price4Input = document.getElementById('price4'); var demandQuantityError = document.getElementById('demandQuantityError'); var price1Error = document.getElementById('price1Error'); var demandQuantity2Error = document.getElementById('demandQuantity2Error'); var price2Error = document.getElementById('price2Error'); var supplyQuantityError = document.getElementById('supplyQuantityError'); var price3Error = document.getElementById('price3Error'); var supplyQuantity2Error = document.getElementById('supplyQuantity2Error'); var price4Error = document.getElementById('price4Error'); var equilibriumPriceDisplay = document.getElementById('equilibriumPrice'); var equilibriumQuantityDisplay = document.getElementById('equilibriumQuantity'); var demandSlopeDisplay = document.getElementById('demandSlope'); var demandInterceptDisplay = document.getElementById('demandIntercept'); var supplySlopeDisplay = document.getElementById('supplySlope'); var supplyInterceptDisplay = document.getElementById('supplyIntercept'); var demandP1Cell = document.getElementById('demandP1'); var demandP2Cell = document.getElementById('demandP2'); var supplyP1Cell = document.getElementById('supplyP1'); var supplyP2Cell = document.getElementById('supplyP2'); var chart; var chartInstance = null; // To hold the Chart.js instance function validateInput(inputElement, errorElement, minValue = -Infinity, maxValue = Infinity) { var value = parseFloat(inputElement.value); var isValid = true; if (isNaN(value)) { errorElement.textContent = "Please enter a valid number."; errorElement.style.display = 'block'; isValid = false; } else if (value maxValue) { errorElement.textContent = "Value is too high."; errorElement.style.display = 'block'; isValid = false; } else { errorElement.textContent = ""; errorElement.style.display = 'none'; } return isValid; } function calculateSlopeIntercept(q1, p1, q2, p2) { var slope = (q2 – q1) / (p2 – p1); var intercept = q1 – slope * p1; return { slope: slope, intercept: intercept }; } function calculateEquilibrium() { // Clear previous errors demandQuantityError.style.display = 'none'; price1Error.style.display = 'none'; demandQuantity2Error.style.display = 'none'; price2Error.style.display = 'none'; supplyQuantityError.style.display = 'none'; price3Error.style.display = 'none'; supplyQuantity2Error.style.display = 'none'; price4Error.style.display = 'none'; // Validate inputs var validDemandQ1 = validateInput(demandQuantityInput, demandQuantityError, 0); var validPrice1 = validateInput(price1Input, price1Error, 0); var validDemandQ2 = validateInput(demandQuantity2Input, demandQuantity2Error, 0); var validPrice2 = validateInput(price2Input, price2Error, 0); var validSupplyQ1 = validateInput(supplyQuantityInput, supplyQuantityError, 0); var validPrice3 = validateInput(price3Input, price3Error, 0); var validSupplyQ2 = validateInput(supplyQuantity2Input, supplyQuantity2Error, 0); var validPrice4 = validateInput(price4Input, price4Error, 0); if (!validDemandQ1 || !validPrice1 || !validDemandQ2 || !validPrice2 || !validSupplyQ1 || !validPrice3 || !validSupplyQ2 || !validPrice4) { equilibriumPriceDisplay.textContent = "–"; equilibriumQuantityDisplay.textContent = "–"; demandSlopeDisplay.textContent = "–"; demandInterceptDisplay.textContent = "–"; supplySlopeDisplay.textContent = "–"; supplyInterceptDisplay.textContent = "–"; updateTableAndChart(null, null, null, null, null, null, null, null); return; } var qd1 = parseFloat(demandQuantityInput.value); var p1 = parseFloat(price1Input.value); var qd2 = parseFloat(demandQuantity2Input.value); var p2 = parseFloat(price2Input.value); var qs1 = parseFloat(supplyQuantityInput.value); var p3 = parseFloat(price3Input.value); var qs2 = parseFloat(supplyQuantity2Input.value); var p4 = parseFloat(price4Input.value); // Ensure prices are different for slope calculation if (p1 === p2) { price2Error.textContent = "Price P2 must be different from P1 for demand."; price2Error.style.display = 'block'; return; } if (p3 === p4) { price4Error.textContent = "Price P4 must be different from P3 for supply."; price4Error.style.display = 'block'; return; } // Calculate demand slope and intercept var demandResult = calculateSlopeIntercept(qd1, p1, qd2, p2); var md = demandResult.slope; var bd = demandResult.intercept; // Calculate supply slope and intercept var supplyResult = calculateSlopeIntercept(qs1, p3, qs2, p4); var ms = supplyResult.slope; var bs = supplyResult.intercept; // Ensure demand slope is negative and supply slope is positive for typical goods if (md > 0) { demandQuantity2Error.textContent = "Demand quantity should typically decrease as price increases."; demandQuantity2Error.style.display = 'block'; price2Error.textContent = "Demand quantity should typically decrease as price increases."; price2Error.style.display = 'block'; return; } if (ms < 0) { supplyQuantity2Error.textContent = "Supply quantity should typically increase as price increases."; supplyQuantity2Error.style.display = 'block'; price4Error.textContent = "Supply quantity should typically increase as price increases."; price4Error.style.display = 'block'; return; } // Check for parallel lines (no intersection) if (md === ms) { equilibriumPriceDisplay.textContent = "N/A"; equilibriumQuantityDisplay.textContent = "N/A"; demandSlopeDisplay.textContent = md.toFixed(2); demandInterceptDisplay.textContent = bd.toFixed(2); supplySlopeDisplay.textContent = ms.toFixed(2); supplyInterceptDisplay.textContent = bs.toFixed(2); updateTableAndChart(md, bd, ms, bs, null, null, p1, p3); return; } // Calculate equilibrium price (Pe) and quantity (Qe) // Pe = (Bs – Bd) / (Md – Ms) var equilibriumPrice = (bs – bd) / (md – ms); // Qe = Md * Pe + Bd var equilibriumQuantity = md * equilibriumPrice + bd; // Ensure equilibrium values are non-negative if (equilibriumPrice < 0 || equilibriumQuantity < 0) { equilibriumPriceDisplay.textContent = "N/A (Negative)"; equilibriumQuantityDisplay.textContent = "N/A (Negative)"; demandSlopeDisplay.textContent = md.toFixed(2); demandInterceptDisplay.textContent = bd.toFixed(2); supplySlopeDisplay.textContent = ms.toFixed(2); supplyInterceptDisplay.textContent = bs.toFixed(2); updateTableAndChart(md, bd, ms, bs, 0, 0, p1, p3); // Show 0 if negative return; } equilibriumPriceDisplay.textContent = "$" + equilibriumPrice.toFixed(2); equilibriumQuantityDisplay.textContent = equilibriumQuantity.toFixed(0); demandSlopeDisplay.textContent = md.toFixed(2); demandInterceptDisplay.textContent = bd.toFixed(2); supplySlopeDisplay.textContent = ms.toFixed(2); supplyInterceptDisplay.textContent = bs.toFixed(2); updateTableAndChart(md, bd, ms, bs, equilibriumPrice, equilibriumQuantity, p1, p3); } function updateTableAndChart(md, bd, ms, bs, pe, qe, p1_input, p3_input) { demandP1Cell.textContent = `($${p1_input}, ${parseFloat(demandQuantityInput.value).toFixed(0)})`; demandP2Cell.textContent = `($${parseFloat(price2Input.value).toFixed(2)}, ${parseFloat(demandQuantity2Input.value).toFixed(0)})`; supplyP1Cell.textContent = `($${p3_input}, ${parseFloat(supplyQuantityInput.value).toFixed(0)})`; supplyP2Cell.textContent = `($${parseFloat(price4Input.value).toFixed(2)}, ${parseFloat(supplyQuantity2Input.value).toFixed(0)})`; var canvas = document.getElementById('marketChart'); var ctx = canvas.getContext('2d'); // Clear previous chart if it exists if (chartInstance) { chartInstance.destroy(); } if (md === null || bd === null || ms === null || bs === null) { // No valid calculation, clear canvas or show message ctx.clearRect(0, 0, canvas.width, canvas.height); return; } // Determine chart range var maxPrice = Math.max(parseFloat(price1Input.value), parseFloat(price2Input.value), parseFloat(price3Input.value), parseFloat(price4Input.value), pe || 0) * 1.2; var maxQuantity = Math.max(parseFloat(demandQuantityInput.value), parseFloat(demandQuantity2Input.value), parseFloat(supplyQuantityInput.value), parseFloat(supplyQuantity2Input.value), qe || 0) * 1.2; // Calculate points for the demand curve (Q = mP + b) var demandPoints = []; var demandStartP = 0; var demandEndP = maxPrice; var demandStartQ = bd; // Q when P=0 var demandEndQ = md * maxPrice + bd; if (demandStartQ < 0) demandStartQ = 0; if (demandEndQ < 0) demandEndQ = 0; demandPoints.push({ x: demandStartP, y: demandStartQ }); demandPoints.push({ x: demandEndP, y: demandEndQ }); // Calculate points for the supply curve (Q = mP + b) var supplyPoints = []; var supplyStartP = 0; var supplyEndP = maxPrice; var supplyStartQ = bs; // Q when P=0 var supplyEndQ = ms * maxPrice + bs; if (supplyStartQ < 0) supplyStartQ = 0; if (supplyEndQ < 0) supplyEndQ = 0; supplyPoints.push({ x: supplyStartP, y: supplyStartQ }); supplyPoints.push({ x: supplyEndP, y: supplyEndQ }); chartInstance = new Chart(ctx, { type: 'scatter', // Use scatter for plotting lines based on points data: { datasets: [{ label: 'Demand Curve', data: demandPoints, borderColor: 'rgba(255, 99, 132, 1)', backgroundColor: 'rgba(255, 99, 132, 0.5)', showLine: true, fill: false, pointRadius: 0, tension: 0 // Straight line }, { label: 'Supply Curve', data: supplyPoints, borderColor: 'rgba(54, 162, 235, 1)', backgroundColor: 'rgba(54, 162, 235, 0.5)', showLine: true, fill: false, pointRadius: 0, tension: 0 // Straight line }] }, options: { scales: { x: { type: 'linear', position: 'bottom', title: { display: true, labelString: 'Price ($)' }, min: 0, max: maxPrice }, y: { title: { display: true, labelString: 'Quantity' }, min: 0, max: maxQuantity } }, plugins: { tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.x !== null) { label += 'Price: $' + context.parsed.x.toFixed(2) + ', '; } if (context.parsed.y !== null) { label += 'Quantity: ' + context.parsed.y.toFixed(0); } return label; } } }, legend: { display: true, position: 'top' } }, responsive: true, maintainAspectRatio: false // Allows setting height/width via CSS if needed } }); } function resetCalculator() { demandQuantityInput.value = "1000"; price1Input.value = "10"; demandQuantity2Input.value = "800"; price2Input.value = "12"; supplyQuantityInput.value = "700"; price3Input.value = "8"; supplyQuantity2Input.value = "900"; price4Input.value = "10"; // Clear errors demandQuantityError.style.display = 'none'; price1Error.style.display = 'none'; demandQuantity2Error.style.display = 'none'; price2Error.style.display = 'none'; supplyQuantityError.style.display = 'none'; price3Error.style.display = 'none'; supplyQuantity2Error.style.display = 'none'; price4Error.style.display = 'none'; calculateEquilibrium(); // Recalculate with default values } function copyResults() { var equilibriumPrice = equilibriumPriceDisplay.textContent; var equilibriumQuantity = equilibriumQuantityDisplay.textContent; var demandSlope = demandSlopeDisplay.textContent; var demandIntercept = demandInterceptDisplay.textContent; var supplySlope = supplySlopeDisplay.textContent; var supplyIntercept = supplyInterceptDisplay.textContent; var demandQ1 = demandQuantityInput.value; var price1 = price1Input.value; var demandQ2 = demandQuantity2Input.value; var price2 = price2Input.value; var supplyQ1 = supplyQuantityInput.value; var price3 = price3Input.value; var supplyQ2 = supplyQuantity2Input.value; var price4 = price4Input.value; var resultsText = "Equilibrium Price Calculation Results:\n\n"; resultsText += "— Calculated Equilibrium —\n"; resultsText += "Equilibrium Price (Pe): " + equilibriumPrice + "\n"; resultsText += "Equilibrium Quantity (Qe): " + equilibriumQuantity + "\n\n"; resultsText += "— Derived Curve Parameters —\n"; resultsText += "Demand Slope (Md): " + demandSlope + "\n"; resultsText += "Demand Intercept (Bd): " + demandIntercept + "\n"; resultsText += "Supply Slope (Ms): " + supplySlope + "\n"; resultsText += "Supply Intercept (Bs): " + supplyIntercept + "\n\n"; resultsText += "— Input Assumptions —\n"; resultsText += "Demand Point 1: Q=" + demandQ1 + " at P=$" + price1 + "\n"; resultsText += "Demand Point 2: Q=" + demandQ2 + " at P=$" + price2 + "\n"; resultsText += "Supply Point 1: Q=" + supplyQ1 + " at P=$" + price3 + "\n"; resultsText += "Supply Point 2: Q=" + supplyQ2 + " at P=$" + price4 + "\n"; navigator.clipboard.writeText(resultsText).then(function() { var feedback = document.getElementById('copyFeedback'); feedback.style.display = 'block'; setTimeout(function() { feedback.style.display = 'none'; }, 3000); }).catch(function(err) { console.error('Failed to copy results: ', err); }); } // Initial calculation on page load document.addEventListener('DOMContentLoaded', function() { // Load Chart.js library dynamically var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/chart.js@3.7.0/dist/chart.min.js'; script.onload = function() { calculateEquilibrium(); // Calculate after chart library is loaded }; document.head.appendChild(script); // Add event listeners for real-time updates var inputs = [ demandQuantityInput, price1Input, demandQuantity2Input, price2Input, supplyQuantityInput, price3Input, supplyQuantity2Input, price4Input ]; inputs.forEach(function(input) { input.addEventListener('input', calculateEquilibrium); }); });

Leave a Comment