How to make a scientific calculator in matlab?

25 ビュー (過去 30 日間)
Pedro Machadp
Pedro Machadp 2015 年 11 月 17 日
回答済み: Surya 2023 年 2 月 23 日
I need to do a scientific calculator that has the basic functions and trigonometric functions , at least . I'm in doubt about what commands to use.
Thank you.
  2 件のコメント
John D'Errico
John D'Errico 2015 年 11 月 17 日
Start with a gui interface. so look at guide to build the gui. But really, you need to start writing code. You won't learn until you start trying.
Geoff Hayes
Geoff Hayes 2015 年 11 月 17 日
Pedro - this sounds like a homework assignment. Since you are creating a calculator, you probably want to use GUIDE to design the user interface for it. Try to create the calculator first, adding the buttons and text control and then work on the callbacks for each button..once you know exactly how each button should behave.

サインインしてコメントする。

回答 (1 件)

Surya
Surya 2023 年 2 月 23 日
Hi,
Here's an example implementation of a calculator that allows the user to input an expression and then evaluates the expression using the eval function in MATLAB.
% Define a function for the calculator
function scientificCalculator()
% Display a welcome message
disp('Welcome to the scientific calculator!');
% Loop until the user enters 'quit'
while true
% Prompt the user to enter an expression
expr = input('Enter an expression (or quit to exit): ', 's');
% Check if the user wants to quit
if strcmp(expr, 'quit')
break;
end
% Evaluate the expression
result = eval(expr);
% Display the result
disp(['Result: ' num2str(result)]);
end
% Display a goodbye message
disp('Goodbye!');
end
This calculator allows the user to input an expression using MATLAB syntax, including basic functions like +, -, *, /, and ^, as well as trigonometric functions like sin, cos, and tan.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by