I want b value only but unrecognizied value are variable b ..B can be find only through trail and error with out any intiate value of b ??
조회 수: 2 (최근 30일)
이전 댓글 표시
p = 0:15;
% Define the constants
r = 1.4;
m = 1.6;
% Loop through each value of p
for i = 1:length(p)
% Define the function to be solved
tan(p(i))= 2*cot(b)*((m^2*sin(b).^2 - 1)/(m^2*(r+cos(2*b)) + 2));
end
% Display the results
disp(['The values of b for different values of p are:']);
disp(b);
댓글 수: 2
Dyuman Joshi
2023년 9월 30일
편집: Dyuman Joshi
2023년 9월 30일
"=" is used for assigning.
In this line of code -
tan(p(i))= 2*cot(b)*((m^2*sin(b).^2 - 1)/(m^2*(r+cos(2*b)) + 2));
you are trying to store an expression in a variable named tan. Which leads to another point that it is not a good idea to use built-in functions as variables.
If you want to solve equations numerically, a general idea is to define anonymous functions and use a solver such as fzero.
The equation might have multiple solutions for different values of p, then which solution values should be stored?
답변 (1개)
Walter Roberson
2023년 9월 30일
There are multiple solutions for some of the p values. The other p values lead to expressions in 6th roots of a complex polynomial.
p = sym(0:15)
% Define the constants
r = sym(1.4)
m = sym(1.6)
syms b
% Loop through each value of p
for i = 1:length(p)
% Define the function to be solved
sol{i} = solve(tan(p(i)) == 2*cot(b)*((m^2*sin(b).^2 - 1)/(m^2*(r+cos(2*b)) + 2)));
end
% Display the results
disp(['The values of b for different values of p are:']);
celldisp(sol)
celldisp(cellfun(@double, sol, 'uniform', 0))
댓글 수: 2
Walter Roberson
2023년 9월 30일
Numeric solution is a bit different...
p = sym(0:15)
% Define the constants
r = sym(1.4)
m = sym(1.6)
syms b
% Loop through each value of p
for i = 1:length(p)
% Define the function to be solved
sol(i) = vpasolve(tan(p(i)) == 2*cot(b)*((m^2*sin(b).^2 - 1)/(m^2*(r+cos(2*b)) + 2)), 1);
end
% Display the results
disp(['The values of b for different values of p are:']);
disp(sol.')
fplot(-tan(p(i)) + 2*cot(b)*((m^2*sin(b).^2 - 1)/(m^2*(r+cos(2*b)) + 2)), [-50 50]);
ylim([-0.5 2])
The plot is for the last value of p(i) so it looks like there is likely an infinite number of solutions. I'm not sure why solve() only finds one.
Walter Roberson
2023년 9월 30일
Ah, once more solve() was choosing a single "representative" answer.
If you look at the conditions display for the entries after the first, you wills see several parts with multiple z1 == parts joined by v . Those v are "or" symbols -- so there are several matching numeric values for each output for the second and later solutions.
p = sym(0:15)
% Define the constants
r = sym(1.4)
m = sym(1.6)
syms b
% Loop through each value of p
for i = 1:length(p)
% Define the function to be solved
sol{i} = solve(tan(p(i)) == 2*cot(b)*((m^2*sin(b).^2 - 1)/(m^2*(r+cos(2*b)) + 2)), 'returnconditions', true);
end
% Display the results
disp(['The values of b for different values of p are:']);
celldisp(sol)
celldisp(cellfun(@(S)vpa(S.b), sol, 'uniform', 0))
celldisp(cellfun(@(S)vpa(S.conditions), sol, 'uniform', 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!