0
0
MATLABdata~30 mins

Element-wise operations (.*, ./, .^) in MATLAB - Mini Project: Build & Apply

Choose your learning style9 modes available
Element-wise Operations in MATLAB
📖 Scenario: Imagine you have two lists of numbers representing daily sales and daily costs for a small shop. You want to calculate the profit for each day by subtracting costs from sales, then find the profit margin by dividing profit by sales, and finally calculate the profit growth by squaring the profit values.
🎯 Goal: You will create two vectors for sales and costs, then use element-wise operations .*, ./, and .^ to calculate profit, profit margin, and profit growth for each day.
📋 What You'll Learn
Create two vectors called sales and costs with exact values
Create a variable called days to store the number of days
Calculate profit using element-wise subtraction
Calculate profit_margin using element-wise division
Calculate profit_growth using element-wise power
Display the results using disp
💡 Why This Matters
🌍 Real World
Element-wise operations are useful when you want to perform calculations on each item in a list or array separately, like calculating daily profits or growth rates.
💼 Career
Understanding element-wise operations is important for data analysis, financial modeling, and scientific computing where you work with arrays of data.
Progress0 / 4 steps
1
Create sales and costs vectors
Create a row vector called sales with values [100, 150, 200, 250, 300] and a row vector called costs with values [60, 90, 120, 160, 180].
MATLAB
Need a hint?

Use square brackets [] to create row vectors with commas separating the numbers.

2
Create days variable
Create a variable called days that stores the number of elements in the sales vector using the length function.
MATLAB
Need a hint?

Use length(sales) to find how many numbers are in the sales vector.

3
Calculate profit, profit margin, and profit growth
Calculate profit by subtracting costs from sales using element-wise subtraction. Then calculate profit_margin by dividing profit by sales using element-wise division. Finally, calculate profit_growth by squaring each element of profit using element-wise power.
MATLAB
Need a hint?

Use - for subtraction, ./ for element-wise division, and .^ for element-wise power.

4
Display the results
Use disp to display the variables profit, profit_margin, and profit_growth.
MATLAB
Need a hint?

Use disp('text') to show labels and disp(variable) to show values.