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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Dyuman Joshi
il 30 Set 2023
Modificato: Dyuman Joshi
il 30 Set 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?
Risposte (1)
Walter Roberson
il 30 Set 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 Commenti
Walter Roberson
il 30 Set 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
il 30 Set 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))
Vedere anche
Categorie
Scopri di più su Number Theory in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!