My answer is not matching with attached file

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

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
MINATI le 13 Jan 2020
All F's and G's are different
i.e, like F(r), F(k-r) and F(k-r+1) are different.(Its a recurrence relation) and same for G also.
But the values I am getting for F(4), F(5),F(6) and G(4, G(5),G(6) etc. are not matching with the actual values (In ATTACHED pdf)
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
MINATI le 13 Jan 2020
Modifié(e) : Walter Roberson le 13 Jan 2020
If I use
for k=1:7
for r = 1:k
F(k+3)= ( F(1)+ F(2)+F(3)+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) = (G(1)+G(2)+G(3)+ 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
%%%THEN
F(4)=(L + M + a + 1)/(6*b1 + 6)
and
G(4)=(L/2 + M/2 + b + 1/2)/(6*b1 + 6)
WHICH is not matching
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
MINATI le 14 Jan 2020
okay
Thanks for your patience
So what next to modify?
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
MINATI le 14 Jan 2020
for reference
Eqn (3.5) - (3.8) are used to find eqns (3.9)& (3.10) in the attached pdf (GOOD.pdf).

Réponses (0)

Cette question est clôturée.

Tags

Aucun tag saisi pour le moment.

Question posée :

le 12 Jan 2020

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by