How could I correct the "solve" function?

2 次查看(过去 30 天)
I want to get the answer with solve function.
if I use while loop below, MATLAB returns the empty syms 0-by-1.
E = 6.00;
syms x;
%% all the variables value is assigned %%
while E >= 2.00
eq = E == E_eq + (R*T)/F*log((1-x)/x) + (R*T)/F*g*(0.5 - x);
theta = vpasolve(eq,x, [-inf inf]);
data_plot = [data_plot; E, theta];
E = E - 0.01;
end
on the other hands,
if I use this loop, it shows the answer but only in a tiny range.
while E >= 2.00
eq = E == E_eq + (R*T)/F*log((1-x)/x); %% I just delete the "(R*T)/F*g*(0.5 - x)" term.
theta = vpasolve(eq,x, [-inf inf]);
data_plot = [data_plot; E, theta];
E = E - 0.01;
end
when I calculate same function with wolfram alpha, it shows the answer around 3E-34.
is there any way to get the answer under the value 1E-35?
or, do I wrong with using solve function?
  1 个评论
Bjorn Gustavsson
Bjorn Gustavsson 2021-1-27
Renormalize your equation, that is change "units", such that your solution is not so close to the finite precision smalles non-zero number.

请先登录,再进行评论。

回答(1 个)

Vidhi Agarwal
Vidhi Agarwal 2025-3-24
I understand you're encountering issues with the "vpasolve" function in MATLAB, which might be due to the complexity of the equation or the range of values you're trying to solve for.
Renormalizing an equation involves changing the units or scaling the variables and parameters in a way that makes the problem more numerically stable and avoids dealing with extremely small or large numbers. This can improve the precision and reliability of numerical solvers like "vpasolve".
Below are the steps that might help you to renormalizing your equation:
  1. Determine which variables and parameters in your equation are contributing to the extremely small or large values.
  2. Decide on a scale factor that brings these values into a more manageable range, ideally between 0.1 and 10 for most numerical algorithms.
  3. Replace the original variables and parameters with their scaled counterparts.
  4. Use "vpasolve" or another solver on the scaled equation.
  5. Once you have a solution, convert it back to the original units if necessary.
Assume the equation involves a very small parameter, "g", which results in solutions around "3E-34". You could scale "g" by a factor of "10^34":
Below is the sample code for the same:
E = 6.00;
syms x;
data_plot = [];
E_eq = ...; % Example values
R = ...;
T = ...;
F = ...;
g = ...;
scale_factor = 1e34;
% Redefine the equation with scaled g
g_scaled = g * scale_factor;
while E >= 2.00
eq = E == E_eq + (R*T)/F*log((1-x)/x) + (R*T)/F*g_scaled*(0.5 - x);
theta_scaled = vpasolve(eq, x, [0, 1]);
if ~isempty(theta_scaled)
data_plot = [data_plot; E, theta_scaled];
else
disp(['No solution found for E = ', num2str(E)]);
end
E = E - 0.01;
end
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by