Filter löschen
Filter löschen

question about code error

1 Ansicht (letzte 30 Tage)
영석
영석 am 20 Okt. 2023
Bearbeitet: Dyuman Joshi am 20 Okt. 2023
hi
i made a code to get value about c2(small letter c2).
b1=180; b2=165; c1=115; A1=120; A2=100;
B1=(60-C1);
syms C1 a C2 c2;
equation1 = c1/sind(C1) == 180/sind(B1);
equation2 = 180/sind(B1) == a/sind(120);
% 방정식 풀기
sol = solve([equation1, equation2], [C1, a]);
% 결과 출력
fprintf('Value of C1: %.2f도\n', sol.C1);
fprintf('Value of a: %.2f\n', sol.a);
B2=(80-C2);
equation3 = a/sind(100) == 165/sind(B2);
equation4 = 165/sind(B2) == c2/sind(C2);
% 방정식 풀기
sol2 = solve([equation3, equation4], [C2, c2]);
% 결과 출력
fprintf('Value of C2: %.2f도\n', sol2.C2);
fprintf('Value of c2: %.2f\n', sol2.c2);
The road using the Cosine Law created a way to obtain
error code:(
Error occurred during: fprintf
Cannot be converted from sym to double.
What's wrong?

Antworten (2)

Walter Roberson
Walter Roberson am 20 Okt. 2023
equation3 = a/sind(100) == 165/sind(B2);
equation4 = 165/sind(B2) == c2/sind(C2);
% 방정식 풀기
sol2 = solve([equation3, equation4], [C2, c2]);
You have two equations in 3 symbolic variables -- c2, C2, and a . Therefore when you solve for C2 and c2 then at least one of the solutions is almost certain to be in terms of the unresolved variable a -- and therefore the result will be something that cannot be converted to numeric.

Dyuman Joshi
Dyuman Joshi am 20 Okt. 2023
Bearbeitet: Dyuman Joshi am 20 Okt. 2023
Since you are working with sides, assume the symbolic variable "a" to bepositive. And although angles can be negative, for the given case i.e. a triangle, we can assume them to be positive as well.
b1=180; b2=165; c1=115; A1=120; A2=100;
syms C1 a C2 c2 positive
B1=(60-C1);
equation1 = c1/sind(C1) == 180/sind(B1);
equation2 = 180/sind(B1) == a/sind(120);
% 방정식 풀기
sol = solve([equation1, equation2], [C1, a]);
% 결과 출력
fprintf('Value of C1: %.2f도\n', sol.C1);
Value of C1: 22.75도
fprintf('Value of a: %.2f\n', sol.a);
Value of a: 257.54
%% Use the value of a obtained to solve for other variables
%Note that you can directly get C1 and a as the outputs from solve()
%[C1, a] = solve([equation1, equation2], [C1, a]);
a = sol.a;
C1 = sol.C1;
B2=(80-C2);
equation3 = a/sind(100) == 165/sind(B2);
equation4 = 165/sind(B2) == c2/sind(C2);
% 방정식 풀기
sol2 = solve([equation3, equation4], [C2, c2]);
% 결과 출력
fprintf('Value of C2: %.2f도\n', sol2.C2);
Value of C2: 40.88도
fprintf('Value of c2: %.2f\n', sol2.c2);
Value of c2: 171.15

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by