採用された回答

Walter Roberson
Walter Roberson 2022 年 2 月 24 日

0 投票

offset = 1; % Indices are 1-based in Matlab
S = 0;
for p = 0:i
S = S + A(offset+p) * C(offset + i - p);
end

6 件のコメント

shiv gaur
shiv gaur 2022 年 2 月 24 日
sir ans must verify the result by taking any arbitary example
elabrate with example ans must be verify by taking any value
Rik
Rik 2022 年 2 月 24 日
Also here: why do you ask Walter to provide values for A and C? Why don't you provide any?
Walter Roberson
Walter Roberson 2022 年 2 月 24 日
A = [5 3 -1 2]
A = 1×4
5 3 -1 2
C = [8 -2 3 2]
C = 1×4
8 -2 3 2
i = 3
i = 3
offset = 1; % Indices are 1-based in Matlab
S = 0;
for p = 0:i
fprintf('p = %d, A(1+%d) = %d, C(1+%d-%d) = %d, product = %d\n', p, p, A(offset+p), i, p, C(offset+i-p), A(offset+p) * C(offset + i - p));
fprintf('S before addition: %d\n', S);
S = S + A(offset+p) * C(offset + i - p);
fprintf('S after addition: %d\n', S);
end
p = 0, A(1+0) = 5, C(1+3-0) = 2, product = 10
S before addition: 0
S after addition: 10
p = 1, A(1+1) = 3, C(1+3-1) = 3, product = 9
S before addition: 10
S after addition: 19
p = 2, A(1+2) = -1, C(1+3-2) = -2, product = 2
S before addition: 19
S after addition: 21
p = 3, A(1+3) = 2, C(1+3-3) = 8, product = 16
S before addition: 21
S after addition: 37
S
S = 37
alternate_S = sum(A.*fliplr(C))
alternate_S = 37
shiv gaur
shiv gaur 2022 年 2 月 24 日
pl help to solve this problem
p=8/3;
r=25;
sigma=10;
npoints =5;
dt = 0.1;
a = zeros(npoints,1);
b = zeros(npoints,1);
c= zeros(npoints,1);
t = zeros(npoints,1);
a(1)=1;
b(1)=1;
c(1)=1;
suma=0;
sumb=0;
sumc=0;
sumS=0;
sumZ=0;
for i = 1:npoints-1
a(i+1)=((sigma)/(i+1))*(b(i)-a(i));
sumS=sumS+a(i)*c(i-npoints);
b(i+1)=(1/(i+1))*(r*a(i)-b(i)-sumS);
sumZ=sumZ+a(i)*b(i-npoints);
c(i+1)=(1/(i+1))*(sumZ-p*c(i));
suma=suma+a(i).*(t^i);
sumb=sumb+b(i).*(t^i);
sumc=sumc+c(i).*(t^i);
t(i+1) = t(i) + dt;
disp(sumS)
end;
Rik
Rik 2022 年 2 月 24 日
This is an honest question: why don't you format your code? I'm serious. Why do you only use one of these three buttons?
And why do you insist on leaving out any interpunction from your text? Can't you see that makes it harder to read?
Walter Roberson
Walter Roberson 2022 年 2 月 24 日
You are already asking for the solution to that power series in several questions. Concentrate on them, instead of asking here in comments on a completely different question.

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2022 年 2 月 23 日

1 投票

S = 0;
for p = 1:i+1 % Indices are 1-based in Matlab
S = S + A(p) + C(i - p);
end

7 件のコメント

shiv gaur
shiv gaur 2022 年 2 月 23 日
this is in multiplying in above figure your ans is why +
shiv gaur
shiv gaur 2022 年 2 月 23 日
why value not calculateable
Torsten
Torsten 2022 年 2 月 23 日
Maybe because you didn't specify A and C ?
shiv gaur
shiv gaur 2022 年 2 月 23 日
you take arbitary value for match
Rik
Rik 2022 年 2 月 24 日
Changing + to * seems easy enough. What is your remaining issue? Why not accept this answer?
shiv gaur
shiv gaur 2022 年 2 月 24 日
elabrate with example ans must be verify by taking any value
Rik
Rik 2022 年 2 月 24 日
Is your shift key broken? And the keys for the . , and ? symbols? That must be very difficult.
You didn't provide values for A, so apparently those don't matter. Why should Jan pick some numbers to show his code works? You could have done exactly like me: write the example below. Then you could actually show what your problem is. If you can't explain it in English, you should explain it in Matlab.
i=10;
A=rand(i+1,1);
C=rand(size(A));
S = 0;
for p = 1:i+1 % Indices are 1-based in Matlab
S = S + A(p) + C(i - p);
end
Array indices must be positive integers or logical values.
And now we can see that Jan made a small mistake: he corrected the indexing of A, but forgot to fix the indexing of C. Walter has now posted an answer that fixes this.
Also, sending me emails will not do anything. You should format your code as code. It isn't hard. Press ctrl-E before you paste any code or use the bar that appears when you write . Using interpunction will also help. If you post code that doesn't run when you click the small run icon, then the problem is not that I haven't seen your research, the problem is that you didn't include all variable definitions. I did not close your question because I was unable to answer your question, I closed it because you seem to be unwilling to use the tools provided to you. If I insisted on answering your questions in a Dutch dialect, you would not be able to understand me and my answer would be useless to you. If you insist on not formatting your posts and not using any interpunction you make your responses almost useless as well.

サインインしてコメントする。

カテゴリ

製品

リリース

R2021b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by