How can I solve this problem in MATLAB? Warning!
2 次查看(过去 30 天)
显示 更早的评论
Hi everybody,
I am trying to solve a system of four equations with four unknown in matlab as below:
F = 96485
syms a b c d
equation1=-0.006882+(2*F*1.9499e-7*(0.034294*a*exp(b*-1.0337)+9.938e-9*c*exp(-1.0337*d)))/(1.9499e-7*9.938e-9+1.9499e-7*a*exp(b*-1.0337)+0.034292*c*exp(-1.0337*d));
equation2=-0.006194+(2*F*2.4714e-7*(0.036518*a*exp(b*-1.02708)+1.0638e-8*c*exp(-1.02708*d)))/(2.4714e-7*1.06387e-8+2.4714e-7*a*exp(b*-1.02708)+0.036518*c*exp(-1.02708*d));
equation3=-0.005133+(2*F*3.1279e-7*(0.038873*a*exp(b*-1.0205)+1.1383e-8*c*exp(-1.0205*d)))/(3.1279e-7*1.138e-8+3.12793e-7*a*exp(b*-1.0205)+0.038873*c*exp(-1.0205*d));
equation4=-0.004766+(2*F*3.64848e-7*(0.040494*a*exp(b*-1.0162)+1.18979e-8*c*exp(-1.0162*d)))/(3.6484e-7*1.18979e-8+3.6484e-7*a*exp(b*-1.0162)+0.040494*c*exp(-1.0162*d));
sol=solve(equation1,equation2,equation3,equation4);
double(sol.a)
disp(double(sol.b))
disp(double(sol.c))
disp(double(sol.d))
When I run it, I get the following warning:
Warning: Unable to find explicit solution. For options, see help.
> In solve (line 317)
In four_Eqns (line 11)
ans =
0×1 empty double column vector
Can someone help me to fix this issue? I need to solve this system of 4 unknown equations.
Thank you very much
Mohi
0 个评论
采纳的回答
John D'Errico
2022-1-21
编辑:John D'Errico
2022-1-21
That you need to solve it is not relevant. Does an analytical solution exist? Almost surely not. We all sometimes want for things we cannot have. Personally, I'm looking for world peace. Failing that, a Lamborghini would be nice. :)
sol=vpasolve(equation1,equation2,equation3,equation4)
struct with fields:
a: [0×1 sym]
b: [0×1 sym]
c: [0×1 sym]
d: [0×1 sym]
so the numerical solver failed to find any solution either.
Do you know a solution exists? How do you know that? One may exist, but you need to provide an intelligent set of starting values. That is difficult to know.
Do you need an exact solution to exist? Suppose you could find a solution that at least comes close to making each of those equations as close to zero as possible?
function val = obj(abcd)
F = 96485;
a = abcd(1);
b = abcd(2);
c = abcd(3);
d = abcd(4);
val = [-0.006882+(2*F*1.9499e-7*(0.034294*a*exp(b*-1.0337)+9.938e-9*c*exp(-1.0337*d)))/(1.9499e-7*9.938e-9+1.9499e-7*a*exp(b*-1.0337)+0.034292*c*exp(-1.0337*d));...
-0.006194+(2*F*2.4714e-7*(0.036518*a*exp(b*-1.02708)+1.0638e-8*c*exp(-1.02708*d)))/(2.4714e-7*1.06387e-8+2.4714e-7*a*exp(b*-1.02708)+0.036518*c*exp(-1.02708*d));...
-0.005133+(2*F*3.1279e-7*(0.038873*a*exp(b*-1.0205)+1.1383e-8*c*exp(-1.0205*d)))/(3.1279e-7*1.138e-8+3.12793e-7*a*exp(b*-1.0205)+0.038873*c*exp(-1.0205*d)); ...
-0.004766+(2*F*3.64848e-7*(0.040494*a*exp(b*-1.0162)+1.18979e-8*c*exp(-1.0162*d)))/(3.6484e-7*1.18979e-8+3.6484e-7*a*exp(b*-1.0162)+0.040494*c*exp(-1.0162*d))];
end
Given that, now I can use lsqnonlin.
abcd = lsqnonlin(@obj,rand(1,4))
Local minimum found.
Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.
<stopping criteria details>
abcd =
0.28396 1.3469 1.3427 0.58855
obj(abcd)
ans =
-0.0032482
-0.0015655
0.00075437
0.0021236
Is it an exact solution? Of course not. In fact, a different set of random staritng values seems to find a different solution. That is no surprise, since a 4 dimensional space can be a big place to look.
I would point out though, since you have provided coefficients that are only accurate to about 4 digits, that a solution which comes roughly that close may be as good as you can hope to find.
1 个评论
Torsten
2022-1-22
@Mohiedin Bagheri comment moved here:
Hi
Thank you very much for your helpful answer. It really helped.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!