Making a Matrix calculator

21 次查看(过去 30 天)
Ray
Ray 2025-3-26
编辑: Umeshraja 2025-8-18,11:28
I would like to make a calculator that would ask the user for the number of matrices involved, and then add, subtract, divide, or multiply said matrices. After some digging around, I think I could use while loops, and some switch/case loops to pull this off. I am wondering if this would be the best way to approach this, or if there were some other loops I might not have considered that could help me out. Any advice or suggestions would be appreciated.
  9 个评论
Ray
Ray 2025-3-28
@dpb as tedious as it would be, I would like the user to input all the elments.
Ray
Ray 2025-3-28
Thank you both, I have a fundamentally working program! I can post it if either of you are interested in critiquing me.

请先登录,再进行评论。

回答(2 个)

Prasanna
Prasanna 2025-4-3
For Matrix Calculator, try this IF ELSE Case.
Take this example. It might be helpful for you.
a = input('Enter First Matrix: ');
b = input('Enter Second Matrix: ');
out = input('Operation to do: '); % ADD = 1/SUBTRACT = 2/MULTIPLY = 3/DIVIDE = 4
if out == 1
output_add = a+b
elseif out == 2
output_subtract = a-b
elseif out == 3
output_product = a*b
elseif out == 4
output_divide = a/b
else
fprintf('No proper input')
end

Umeshraja
Umeshraja 2025-8-18,11:28
编辑:Umeshraja 2025-8-18,11:28
Hello @Ray,
If you’re just starting out with MATLAB and want a solid foundation, I recommend first completing the MATLAB Onramp course. It offers a great introduction to MATLAB basics and will help you feel more comfortable working with the environment.
To help build your matrix calculator, here are some useful resources to guide you:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by