Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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
Unrecognized function or variable 'b'.
% Display the results
disp(['The values of b for different values of p are:']);
disp(b);
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 30 Sep 2023
Modifié(e) : Dyuman Joshi le 30 Sep 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
Torsten le 30 Sep 2023
Is p in degrees ? In this case, you have to use "tand" instead of "tan".

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 30 Sep 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)
p = 
% Define the constants
r = sym(1.4)
r = 
m = sym(1.6)
m = 
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:']);
The values of b for different values of p are:
celldisp(sol)
sol{1} =
sol{2} =
sol{3} =
sol{4} =
sol{5} =
sol{6} =
sol{7} =
sol{8} =
sol{9} =
sol{10} =
sol{11} =
sol{12} =
sol{13} =
sol{14} =
sol{15} =
sol{16} =
celldisp(cellfun(@double, sol, 'uniform', 0))
ans{1} = 1.5708 -0.6751 0.6751 ans{2} = -1.7814 + 0.6341i ans{3} = -1.4109 + 0.6670i ans{4} = -2.5895 ans{5} = -1.8300 + 0.5896i ans{6} = -1.4629 + 0.6898i ans{7} = -1.1539 + 0.1396i ans{8} = -1.8758 + 0.5312i ans{9} = -1.5158 + 0.7033i ans{10} = -1.1842 + 0.3388i ans{11} = -1.9180 + 0.4540i ans{12} = -1.5691 + 0.7079i ans{13} = -1.2211 + 0.4484i ans{14} = -1.9553 + 0.3470i ans{15} = -1.6225 + 0.7038i ans{16} = -1.2630 + 0.5269i
  2 commentaires
Walter Roberson
Walter Roberson le 30 Sep 2023
Numeric solution is a bit different...
p = sym(0:15)
p = 
% Define the constants
r = sym(1.4)
r = 
m = sym(1.6)
m = 
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:']);
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
Walter Roberson le 30 Sep 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)
p = 
% Define the constants
r = sym(1.4)
r = 
m = sym(1.6)
m = 
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:']);
The values of b for different values of p are:
celldisp(sol)
sol{1} = b: [3×1 sym] parameters: k conditions: [3×1 sym] sol{2} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(2i))/5 - 157/80) + z^2*((157*exp(2i))/80 - 7/5) + exp(2i), z, 1) | z1 == root(z^6 - z^4*((7*e… sol{3} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(4i))/5 - 157/80) + z^2*((157*exp(4i))/80 - 7/5) + exp(4i), z, 1) | z1 == root(z^6 - z^4*((7*e… sol{4} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(6i))/5 - 157/80) + z^2*((157*exp(6i))/80 - 7/5) + exp(6i), z, 1) | z1 == root(z^6 - z^4*((7*e… sol{5} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(8i))/5 - 157/80) + z^2*((157*exp(8i))/80 - 7/5) + exp(8i), z, 1) | z1 == root(z^6 - z^4*((7*e… sol{6} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(10i))/5 - 157/80) + z^2*((157*exp(10i))/80 - 7/5) + exp(10i), z, 1) | z1 == root(z^6 - z^4*((… sol{7} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(12i))/5 - 157/80) + z^2*((157*exp(12i))/80 - 7/5) + exp(12i), z, 1) | z1 == root(z^6 - z^4*((… sol{8} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(14i))/5 - 157/80) + z^2*((157*exp(14i))/80 - 7/5) + exp(14i), z, 1) | z1 == root(z^6 - z^4*((… sol{9} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(16i))/5 - 157/80) + z^2*((157*exp(16i))/80 - 7/5) + exp(16i), z, 1) | z1 == root(z^6 - z^4*((… sol{10} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(18i))/5 - 157/80) + z^2*((157*exp(18i))/80 - 7/5) + exp(18i), z, 1) | z1 == root(z^6 - z^4*((… sol{11} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(20i))/5 - 157/80) + z^2*((157*exp(20i))/80 - 7/5) + exp(20i), z, 1) | z1 == root(z^6 - z^4*((… sol{12} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(22i))/5 - 157/80) + z^2*((157*exp(22i))/80 - 7/5) + exp(22i), z, 1) | z1 == root(z^6 - z^4*((… sol{13} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(24i))/5 - 157/80) + z^2*((157*exp(24i))/80 - 7/5) + exp(24i), z, 1) | z1 == root(z^6 - z^4*((… sol{14} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(26i))/5 - 157/80) + z^2*((157*exp(26i))/80 - 7/5) + exp(26i), z, 1) | z1 == root(z^6 - z^4*((… sol{15} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(28i))/5 - 157/80) + z^2*((157*exp(28i))/80 - 7/5) + exp(28i), z, 1) | z1 == root(z^6 - z^4*((… sol{16} = b: 2*pi*k - log(z1)*1i parameters: [k z1] conditions: in(k, 'integer') & cos(log(z1)*2i - 4*pi*k) ~= -349/160 & (z1 == root(z^6 - z^4*((7*exp(30i))/5 - 157/80) + z^2*((157*exp(30i))/80 - 7/5) + exp(30i), z, 1) | z1 == root(z^6 - z^4*((…
celldisp(cellfun(@(S)vpa(S.b), sol, 'uniform', 0))
ans{1} =
ans{2} =
ans{3} =
ans{4} =
ans{5} =
ans{6} =
ans{7} =
ans{8} =
ans{9} =
ans{10} =
ans{11} =
ans{12} =
ans{13} =
ans{14} =
ans{15} =
ans{16} =
celldisp(cellfun(@(S)vpa(S.conditions), sol, 'uniform', 0))
ans{1} =
ans{2} =
ans{3} =
ans{4} =
ans{5} =
ans{6} =
ans{7} =
ans{8} =
ans{9} =
ans{10} =
ans{11} =
ans{12} =
ans{13} =
ans{14} =
ans{15} =
ans{16} =

Connectez-vous pour commenter.

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by