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
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
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:
- Determine which variables and parameters in your equation are contributing to the extremely small or large values.
- Decide on a scale factor that brings these values into a more manageable range, ideally between 0.1 and 10 for most numerical algorithms.
- Replace the original variables and parameters with their scaled counterparts.
- Use "vpasolve" or another solver on the scaled equation.
- 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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!