how to solve the following equation by using Matlab
2 次查看(过去 30 天)
显示 更早的评论
Hi all
When we solved this equation \begin{align}
f(z)=(0.10-0.3i) z^{-1} + (0.2121 - 0.0008i) z^{-2} +(0.9+0.001i)z^{-3}=0
by using Matlab, we got the following result ,
numerical solution by Matlab,
1/z_1= (0.0000 + 0.0000i)
1/z_2= (-0.4716 - 0.4706i)
1/z_3=(0.2359 + 0.4717i)
and when I solve this equation byhand we got;
1/z_1= 0.0000 + 0.0000i
1/z_2=(-0.4929597603-0.4990725263i)
1/z_3=(0.2561831187+0.5002232656i)
My questionis is,
By using the Matlab, How can I repeat the solution ( for example 100 times ) to check that every time the numerical solution still close to the solution that I have got by hand or become different?
By other way can I use any loop to repeat the solution 100 time by using the Matlab?
I appreciate any help
Thanks
0 个评论
采纳的回答
Luca Ferro
2023-1-19
Try with this function:
function checksol(N) %N is the number of times it will solve the equation (dont use a huge number, 10 is sufficient)
syms z ;
sol={};
diffcount=0;
eq= (0.10-0.3i)* z^-1 + (0.2121 - 0.0008i) *z^-2 +(0.9+0.001i)*z^-3==0;
lastsol=solve(eq,z);
for jj=1:N
currsol=solve(eq,z);
if currsol ~= lastsol
diffcount=diffcount+1; %augments counter for every time it finds a different solution
end
lastsol=currsol;
end
if diffcount~=0
disp('Different result detected')
else
disp('Result is always the same')
end
end
On my machine it resolves it consistently, i would double check your by hand solution rather than matlab.
更多回答(1 个)
John D'Errico
2023-1-20
Your problem is:
f = @(z) (0.10-0.3i)*z.^(-1) + (0.2121 - 0.0008i)*z.^(-2) +(0.9+0.001i)*z.^(-3);
Please don't use curly braces in an equation. That is not valid MATLAB syntax. As well, MATLAB uses * to multiply. There is no implicit multiplication by a constant. MATLAB finds the solutions as:
syms Z
zsol = solve(f(Z),Z,'maxdegree',3)
The solution you claim to have found using MATLAB is a spurious one, since z == 0 is a divide by zero. So z = 1/0 is NOT a solution to that equation, even though you find it by substituting z = 1/u, and then solving for the roots using u. Sorry. There are only TWO solutions.
vpa(zsol)
And what are the inverses ofthose numbers, so we can compare it to what you claim to have found using MATLAB?
1./vpa(zsol)
And that is the same thing that MATLAB returns.
We can verify these are indeed the true solutions to the problem you show.
f(vpa(zsol))
So numbers on the order of 1e-40. Since this is the default number of digits for vpa, that is just floating point trash.
Is there any meaningful reason to perform this solution a million times, or even just 100? NO. These are the solutions, and they don't change with time.
Anyway, are the solutions you claim to have found by hand really solutions to the problem you show?
z2invclaimed = -0.4929597603-0.4990725263i;
f(1/z2invclaimed)
So not in fact a solution. It is close. You have made approximations, truncating results to only a few significant digits, so your claimed to be solutions that you found by hand are only approximate solutions. Effectively, they are solutions to approximately the problem you have written down.
Again, repeating the solution as many times as you wish will not matter. The result will not change.
2 个评论
Torsten
2023-1-22
The question is why the numerical solution is more accuracy than the solution the we have got manually? is this make sense?
Didn't John D'Errico try to answer this with his last sentences ?
You have made approximations, truncating results to only a few significant digits, so your claimed to be solutions that you found by hand are only approximate solutions. Effectively, they are solutions to approximately the problem you have written down.
And ? Did you cut digits from the polynomial coefficients for the numerical solution ?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!