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
Walter Roberson
2020년 1월 12일
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
2020년 1월 13일
Walter Roberson
2020년 1월 13일
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
2020년 1월 13일
편집: Walter Roberson
2020년 1월 13일
Walter Roberson
2020년 1월 13일
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
2020년 1월 14일
Walter Roberson
2020년 1월 14일
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
2020년 1월 14일
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!