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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Dyuman Joshi
el 30 de Sept. de 2023
Editada: Dyuman Joshi
el 30 de Sept. de 2023
"=" 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?
Torsten
el 30 de Sept. de 2023
Is p in degrees ? In this case, you have to use "tand" instead of "tan".
Respuestas (1)
Walter Roberson
el 30 de Sept. de 2023
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 comentarios
Walter Roberson
el 30 de Sept. de 2023
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
el 30 de Sept. de 2023
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))
Ver también
Categorías
Más información sobre Number Theory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!