How do I correctly use vpasolve?
55 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to numerically solve the following set of equations
M_mag = 1 ; %just some constant simplified here as 1
om = 2*pi*new_freq ; %new_freq is an array of values
C1 = exp(-1i*L.*om./c); % L and c are constant
% phi = exp(1i*om*L/c);
nume = exp(1i.*om.*n*L/c)*4.*n./((1+n).^2); % terms depending on n
denom = 1 + exp(2*1i.*om.*n*L/c).*((n-1)./(n+1)).^2; % terms depending on n
syms n
S = vpasolve(M_mag./C1 == nume./denom , n , guess) %guess is a numerical approach done via another equation, in this case it is 1.7
Whenever I try to use this, I get the following text:
Error using mupadengine/feval_internal
More equations than variables is only supported for polynomial
systems.
Error in sym/vpasolve (line 172)
sol = eng.feval_internal('symobj::vpasolve',eqns,vars,X0);
I have seen similar things being explain in the following link, but I don't understand the explanation. Same for this explanation.
Why can I not solve the equation this way? Is it the exponentials terms?
Thank you very much for your help.
1 Kommentar
Star Strider
am 17 Nov. 2022
I usually use solve, and then vpa the result. It is generally more reliable, especially with functions with multiple roots.
Too much of this code is ‘over the horizon’ and out of sight to provide a specific response.
Antworten (2)
Walter Roberson
am 17 Nov. 2022
M_mag = 1 ; %just some constant simplified here as 1
om = 2*pi*new_freq ; %new_freq is an array of values
C1 = exp(-1i*L.*om./c); % L and c are constant
% phi = exp(1i*om*L/c);
syms n
nume = exp(1i.*om.*n*L/c)*4.*n./((1+n).^2); % terms depending on n
denom = 1 + exp(2*1i.*om.*n*L/c).*((n-1)./(n+1)).^2; % terms depending on n
S = arrayfun(@(EQN) vpasolve(EQN,n,guess), M_mag./C1 == nume./denom)
2 Kommentare
Walter Roberson
am 18 Nov. 2022
result = arrayfun(FUNCTION, ARRAY)
is effectively the same as
if isempty(ARRAY)
result = [];
else
out1 = FUNCTION(ARRAY(1));
result = zeros(size(ARRAY), class(out1));
result(1) = out1;
for K = 2 : numel(ARRAY)
result(K) = FUNCTION(ARRAY(K));
end
end
and
result = arrayfun(FUNCTION, ARRAY, 'uniform', 0)
is effectively the same as
result = cell(size(ARRAY));
for K = 1 : numel(ARRAY)
result{K} = FUNCTION(ARRAY(K));
end
and
result = arrayfun(FUNCTION, ARRAY1, ARRAY2)
is effectively the same as
assert(isequal(size(ARRAY1), size(ARRAY2)), 'input arrays must be the same size');
if isempty(ARRAY1)
result = [];
else
out1 = FUNCTION(ARRAY1(1), ARRAY2(1));
result = zeros(size(ARRAY1), class(out1));
result(1) = out1;
for K = 2 : numel(ARRAY1)
result(K) = FUNCTION(ARRAY1(K), ARRAY2(K));
end
end
So you input a function handle (typically), and one or more arrays that must be exactly the same size. The output is the same size as the array. When 'uniform', 0 is specified, the output is a cell array containing the result of executing the function on each corresponding sets of values from the array in turn. If 'uniform', 0 is not specified, the output is a regular array containing the result of executing the function on each corresponding set of values from the array in turn.
Siehe auch
Kategorien
Mehr zu Applications finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!