My answer is not matching with attached file
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
syms k r
a=sym('a'); b = sym('b');L=sym('L'); M = sym('M'); b1 = sym('b1');
m=7; F = sym(zeros(m,1)); F(1)=0; F(2)=1; F(3)=a;
G = sym(zeros(m,1)); G(1)=0; G(2)=1/2; G(3)=b;
for k=1:7
for r = 1:k
F3 = F(1)+ F(2)+F(3); G3 = G(1)+G(2)+G(3);
F(k+3)= ( F3+sum((r+1)*F(r+1)*(k-r+1)*F(k-r+1)) - sum((k-r+1)*(k-r+2)*F(k-r+1)*(F(r)+G(r)))+ (M+L)*(k)*F(k+1))/((1+b1)*(k+1)*(k+2)*(k));
G(k+3) = (G3+ sum((r+1)*G(r+1)*(k-r+1)*G(k-r+1)) - sum((k-r+1)*(k-r+2)*G(k-r+2)*(F(r)+G(r))) + (M+L)*(k)*G(k+1))/((1+b1)*(k+1)*(k+2)*(k));
end
end
% %%%%%
for N=1:6
disp(F(N))
disp(G(N))
end
f=sum(x^k*F(k),k,0,7)
g=sum(x^k*G(k),k,0,7)
%%%%%%%
Any reply will be greatly appreciated
After getting F(N) and G(N), I neeed to find then f and g
8 commentaires
Walter Roberson
le 12 Jan 2020
x is not defined.
That syntax for sum() does not exist.
F is not a function, so F(0) cannot be accessed.
My guess is
syms x
f = sum(x.^(0:7) .* F(1:8));
g = sum(x.^(0:7) .* G(1:8));
Why are you overwriting all of F and G in every iteration of the double nested loop?
MINATI
le 13 Jan 2020
Walter Roberson
le 13 Jan 2020
Look at your code.
for k=1:7
for r = 1:k
F3 = F(1)+ F(2)+F(3); G3 = G(1)+G(2)+G(3);
F(k+3)= ( F3+sum((r+1)*F(r+1)*(k-r+1)*F(k-r+1)) - sum((k-r+1)*(k-r+2)*F(k-r+1)*(F(r)+G(r)))+ (M+L)*(k)*F(k+1))/((1+b1)*(k+1)*(k+2)*(k));
G(k+3) = (G3+ sum((r+1)*G(r+1)*(k-r+1)*G(k-r+1)) - sum((k-r+1)*(k-r+2)*G(k-r+2)*(F(r)+G(r))) + (M+L)*(k)*G(k+1))/((1+b1)*(k+1)*(k+2)*(k));
end
end
How many times do you set F3 and G3 to the same value?
For any given value of k how often do you write overtop of F(k+3) ?
MINATI
le 13 Jan 2020
Modifié(e) : Walter Roberson
le 13 Jan 2020
Walter Roberson
le 13 Jan 2020
Okay, now, suppose we have a look at when k = 4, and substituting that value into the code:
for r = 1:4
F(4+3)= ( F(1)+ F(2)+F(3)+sum((r+1)*F(r+1)*(4-r+1)*F(4-r+1)) - sum((4-r+1)*(4-r+2)*F(4-r+1)*(F(r)+G(r)))...
+ (M+L)*(4)*F(4+1))/((1+b1)*(4+1)*(4+2)*(4));
G(4+3) = (G(1)+G(2)+G(3)+ sum((r+1)*G(r+1)*(4-r+1)*G(4-r+1)) - sum((4-r+1)*(4-r+2)*G(4-r+2)*(F(r)+G(r)))...
+ (M+L)*(4)*G(k+1))/((1+b1)*(4+1)*(4+2)*(4));
end
Now, how many times do you write to F(4+3) ? If you write more than once to F(4+3) then is in the form of adding to a previous result, along the lines of
value = 0;
for r = 1 : 4
value = value + something involving r
end
Or similarly is it developing the value iteratively, something along the lines of
value = 1;
for r = 1 : 4
value = some_function(value);
end
or are you instead just assigning new values without reference to the result already stored in the location?
MINATI
le 14 Jan 2020
Walter Roberson
le 14 Jan 2020
You have not posted the recurrence formula, so we are restricted to pointing out parts of the code that look suspicious, without being able to make any suggestions as to what code would work.
MINATI
le 14 Jan 2020
Réponses (0)
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!