Adding Polynomials Using App Designer
조회 수: 8 (최근 30일)
이전 댓글 표시
I am new to matlab and I am trying to create a calculator that adds polynomials. I want the user to input something like 3*x+1 and 4*x+1 and have a result of 7*x+2. here is my code but when I try it, it does not display any answer:
% Button pushed function: AddButton
function AddButtonPushed(app, event)
a = str2num(app.fxEditField.Value);
b = str2num(app.gxEditField.Value);
res = a+b;
app.ResultEditField.Value = num2str(res);
end
댓글 수: 0
채택된 답변
Kevin Holly
2022년 7월 20일
How did you want your user to input the data? As for the calculations, see below for an example.
app.fxEditField.Value = [3 1];
app.gxEditField.Value = [4 1];
AddButtonPushed(app)
function AddButtonPushed(app, event)
a = poly2sym(app.fxEditField.Value)
b = poly2sym(app.gxEditField.Value)
res = a+b
app.ResultEditField.Value =res
end
댓글 수: 3
Kevin Holly
2022년 7월 23일
Please see app attached.
app.fxEditField.Value = '3*x+1';
app.gxEditField.Value = '4*x+1';
AddButtonPushed(app);
Below is the callback for the "Add" button.
function AddButtonPushed(app, event)
a = str2sym(app.fxEditField.Value);
b = str2sym(app.gxEditField.Value);
res = a+b;
app.ResultEditField.Value = char(res);
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!