Error message: Too many input arguments

14 ビュー (過去 30 日間)
Quy Hoang
Quy Hoang 2022 年 4 月 23 日
回答済み: Jan 2022 年 4 月 23 日
I want to round the results to 4 numbers after the decimal point, but when I run, i get the following error messages like image below:
syms A1 B1 A2 B2 A3 B3 A4 B4
eq1 = A1*log(4)+B1==341;
eq2 = A4*log(10)+B4==0;
eq3 = A1*log(6)+B1==6*A2+B2;
eq4 = 7*A2+B2==A3*(49/2)+B3;
eq5 = 32*A3+B3==A4*log(8)+B4;
eq6 = A1/600-A2/6==0;
eq7 = A2-A3==0;
eq8 = A3/8-A4/8000==0;
eq = [eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8];
var = [A1, B1, A2, B2, A3, B3, A4, B4];
[A1, B1, A2, B2, A3, B3, A4, B4] = solve(eq, var)
matr = [A1 B1 A2 B2 A3 B3 A4 B4];
result = round(matr,4)

採用された回答

Alberto Cuadra Lara
Alberto Cuadra Lara 2022 年 4 月 23 日
Maybe the round function was not compatible with symbolic variables on previous version.
Try this approach:
  1. Convert matr to float using vpa
  2. Use round function
syms A1 B1 A2 B2 A3 B3 A4 B4
eq1 = A1*log(4)+B1==341;
eq2 = A4*log(10)+B4==0;
eq3 = A1*log(6)+B1==6*A2+B2;
eq4 = 7*A2+B2==A3*(49/2)+B3;
eq5 = 32*A3+B3==A4*log(8)+B4;
eq6 = A1/600-A2/6==0;
eq7 = A2-A3==0;
eq8 = A3/8-A4/8000==0;
eq = [eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8];
var = [A1, B1, A2, B2, A3, B3, A4, B4];
[A1, B1, A2, B2, A3, B3, A4, B4] = solve(eq, var);
matr = [A1 B1 A2 B2 A3 B3 A4 B4];
result = vpa(matr, 32);
result = round(result, 4)
result = 
  1 件のコメント
Quy Hoang
Quy Hoang 2022 年 4 月 23 日
The old error still appears. I replaced the last command and it run:
fprintf('%0.4f\n',matr)
Thanks for your help!

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

その他の回答 (2 件)

Alberto Cuadra Lara
Alberto Cuadra Lara 2022 年 4 月 23 日
Hi Quy!
What version of MATLAB are you using? Your code works in MATLAB 2021b
syms A1 B1 A2 B2 A3 B3 A4 B4
eq1 = A1*log(4)+B1==341;
eq2 = A4*log(10)+B4==0;
eq3 = A1*log(6)+B1==6*A2+B2;
eq4 = 7*A2+B2==A3*(49/2)+B3;
eq5 = 32*A3+B3==A4*log(8)+B4;
eq6 = A1/600-A2/6==0;
eq7 = A2-A3==0;
eq8 = A3/8-A4/8000==0;
eq = [eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8];
var = [A1, B1, A2, B2, A3, B3, A4, B4];
[A1, B1, A2, B2, A3, B3, A4, B4] = solve(eq, var);
matr = [A1 B1 A2 B2 A3 B3 A4 B4];
result = round(matr, 4)
result = 
  1 件のコメント
Quy Hoang
Quy Hoang 2022 年 4 月 23 日
編集済み: Quy Hoang 2022 年 4 月 23 日
I'm using Matlab 2017b. Do you have an alternative command to make it run?

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


Jan
Jan 2022 年 4 月 23 日
result = round(matr * 10000) / 10000

カテゴリ

Find more on Get Started with Symbolic Math Toolbox in Help Center and File Exchange

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by