question about code error
조회 수: 2 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (2개)
Walter Roberson
2023년 10월 20일
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.
댓글 수: 0
Dyuman Joshi
2023년 10월 20일
편집: Dyuman Joshi
2023년 10월 20일
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);
fprintf('Value of a: %.2f\n', sol.a);
%% 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);
fprintf('Value of c2: %.2f\n', sol2.c2);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!