Vector Multiply by Vector

4 ビュー (過去 30 日間)
mostafa
mostafa 2022 年 10 月 10 日
回答済み: David Hill 2022 年 10 月 10 日
Design a program that will accept an input from the user. This input will be the first element in a vector. The user will then input another number. The next element in the vector will then be equal to the first number multiplied by the first number. Assuming that the first input is x and the second input is y, the 3rd and the subsequent elements will be x*yn where n is the element number. The number of elements should increase until n reaches 100 or x*yn is larger than 10000.
I have compile this coding but have many errors... how can i improve my coding based on the given above.
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
vector = []
vector.append(x)
res = (x*(y**2))
vector.append(res)
i = 3
while i < 100 and res <= 10000:
res = (x*(y**i))
vector.append(res)
i = i+1
print(vector)
  4 件のコメント
mostafa
mostafa 2022 年 10 月 10 日
that is my latest update, but still not working
x = input('enter the number: ');
y = input('enter the number: ');
vector = []
vector.append(x)
res = (x*(y*2))
vector.append(res)
i = 3
while i < 100:
res = (x*(y*i))
vector.append(res)
i = i+1
print(vector)
end
while res <= 10000:
res = (x*(y*i))
vector.append(res)
i = i+1
print(vector)
end
Jan
Jan 2022 年 10 月 10 日
There is no "vector.append" in Matlab. print() will not do, what you expect. Remove the colon after the while commands.
If you mention an error, post the complete message here.

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

回答 (1 件)

David Hill
David Hill 2022 年 10 月 10 日
x = input('Enter first number: ');
y = input('Enter second number: ');
r=[x,y,x*y*(1:100)];
r=r(r<=1e4);

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by