The below code takes much time to just compute till N=5. But I wanna know how to do it for N=100 or more a bit faster.

2 次查看(过去 30 天)
syms z;
N = 5; % Compute up to g_5'
alpha = -1; % α_n = -1 for all n
C = sym('C', [1, N]); % Integration constants C0..CN
% Initialize
g_prime = cell(1, N+1);
g = cell(1, N+1);
g_prime{1} = z^2; % g_0'(z)
g{1} = z^3/3 % g_0(z)
g = 1×6 cell array
{[z^3/3]} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
% Iterate
for n = 1:N
% Step 1: Compute g_n'(z) = [ (g_{n-1} + C_{n-1})^2 / g_{n-1}' ]^{α}
numerator = (g{n} + C(n))^2;
denominator = g_prime{n};
g_prime{n+1} = (numerator / denominator); % α = -1 ⇒ flip fraction
% Step 2: Simplify CRITICALLY here to prevent blowup
g_prime{n+1} = simplify(g_prime{n+1});
% Step 3: Compute g_{n}(z) for next step (if not last iteration)
if n < N
g{n+1} = int(g_prime{n+1}, z) + C(n+1);
g{n+1} = simplify(g{n+1}); % Simplify after integration
end
end
% Display fully simplified results
for k = 1:N
fprintf('g_%d''(z) = ', k);
disp(g_prime{k+1});
end
g_1'(z) =
g_2'(z) =
g_3'(z) =
g_4'(z) =
g_5'(z) =

回答(1 个)

John D'Errico
John D'Errico 2025-7-6
编辑:John D'Errico 2025-7-6
I want a bright red new Ferrari in my driveway for Christmas. Its not gonna be there of course. But we all want things we can't have, or are completely unreasonable.
Let me see, so g_1'(z) has 2 terms in the numerator (squared, but the square is not important), and 1 in the denominator.
g_2'(z) has 4 terms on top, and 2 on the bottom. Not so bad for now. But even there, the coefficients are starting to get larger. More digits in a symbolic computation makes things worse too.
g_3'(z) has 8 terms on top, and 4 on the bottom. And each term is getting more complex too.
g_4'(z) has (let me guess) 16 terms on top, and 8 on the bottom.
Do you see a pattern here? It would appear that g_n'(z) has 2^(n-1) terms in the numerator, and 2^(n-2) terms in the denominator.
When n=100, what is 2^(n-1)? I might as well use MATLAB here:
n = 100;
2^(n-1)
ans = 6.3383e+29
That is a number which is roughly a million times larger than Avogadro's number. Do you understand just how large that is? It is large enough that there is not sufficient computing power on the entire planet to compute and store all of those trms. Couple together all of the super computers we have, and they would still stagger under the load.
Anyway, that red Ferrari would quickly get lost in the many potholes on our road, so I'll just skip it for this year. In your case, you might want to see if there are alternative ways to approach your problem. That is the genious and the skill of computation and mathematics in general, to learn to solve intractable problems using other approaches than brute force.
You might, for example, see if you can solve the problem using numerical methods. Or you might decide to look for other approaches. But this approach is doomed to fail, at least until the great robotic overlords take over. Maybe they can off you the computational power you will need for this.
  1 个评论
John D'Errico
John D'Errico 2025-7-6
I was feeling sad that I could not offer a solution here, so I decided to buy one of those new quantum laptop computers to help you out. Not cheap, by the way. That bright red Ferrari would have been a better choice. A company named after Erwin Schroedinger makes them.
The problem is, it arrived in a sealed box. And there is some probability the computer will be completely dead when I open the box. Or it may be working perfectly well, but I canot know which it is until I open the box. And of course, the Schroedinger corporation has a tricky policy. They do not accept unopened merchandise for return. And if you open the box, AND the merchandise is broken, that constitutes operator error, and is the buyer's fault.
So I've chosen to leave the box unopened on our front porch, hoping some package thief will steal it, so I can at least make an insurance claim.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by