Function implementation in matlab

I want to implement this function ?[?, ?] = (?^( ?+?)*u[?] using 41*41 array, where u[n] =1 since all the value will be positive ,and n,m from 0 to 40,
N=40
a=0.9
x =zeros(41,41)
for k=0:N
for col = 1:41
for row = 1:41
x(row,col)=a.^(k+k)*1;
end
end
end
but id give wrong values

6 件のコメント

Suha Ismail
Suha Ismail 2020 年 5 月 8 日
Anyone can help??
Suha Ismail
Suha Ismail 2020 年 5 月 8 日
?
Walter Roberson
Walter Roberson 2020 年 5 月 8 日
You are overwriting all of x for each k value.
Hint: n = col - 1
Suha Ismail
Suha Ismail 2020 年 5 月 8 日
N=40
M=40
a=0.9
x =zeros(41,41)
for col = 1:41
for row = 1:41
for k=0:N
for i=0:M
x(row,col)=a.^(k+i)*1;
end
end
end
end
Suha Ismail
Suha Ismail 2020 年 5 月 8 日
I chcnage to this code but still not work
Walter Roberson
Walter Roberson 2020 年 5 月 8 日
You do not need most of that. You only need two nested loops. Given the row number, you can immediately compute n -- it is just the row number minus 1. Given the column number, you can immediately compute m -- it is just the column number minus 1
for ...
n = row - 1;
for ...
m = col - 1;
output(row, col) = something involving n and m
end
end

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

回答 (1 件)

Stephen23
Stephen23 2020 年 5 月 8 日

0 投票

>> a = 0.9;
>> V = 0:40;
>> M = a.^(V+V(:)); % requires >=R2016b
For earlier versions replace the + with bsxfun.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2020 年 5 月 8 日

コメント済み:

2020 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by