Hi all,
have this bit of code that reads:
function R = resistors()
r = transpose(100:100:400);%transpose to column vector
R = 1./((1/r)); % (.) makes the vector even
end
and its results read;
>> resistors
ans =
Inf Inf Inf 400
i want to stop or not have the Inf, but the real numbers, can someone point me in the right direction? need it for an assesment.
Thanks
Jon

3 件のコメント

darova
darova 2020 年 3 月 12 日
1/(1/r)
Is the same as just r
>> r = 1:5
r =
1 2 3 4 5
>> 1./(1./r)
ans =
1 2 3 4 5
Jonathan Stanton
Jonathan Stanton 2020 年 3 月 12 日
cheers, works lovely!!
Stephen23
Stephen23 2020 年 3 月 12 日
"1/(1/r) Is the same as just r"
This is totally incorrect.
How is solving systems of linear equations anything like calculating the inverse?

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

回答 (1 件)

Stephen23
Stephen23 2020 年 3 月 12 日
編集済み: Stephen23 2020 年 3 月 12 日

1 投票

You used the wrong operator: mrdivide / solves a system of linear equations.
You need to learn the differrences between matrix operations and array operations, otherwise all of your MATLAB code will produce meaningless rubbish outputs:
Use rdivide ./

2 件のコメント

John D'Errico
John D'Errico 2020 年 3 月 12 日
編集済み: John D'Errico 2020 年 3 月 12 日
In my hoped for new post as official WhiteHouse MATLAB counsel, I will recommend that infs and NaNs be forever outlawed. They only confuse people anyway. I might even try to require that pi==3, as this would make many computations much simpler for children in school. By the way, the Earth will soon be mandated to be flat, if I get my way.
My campaign is beginning today. Please get your write-in votes in as soon as possible!
Stephen23
Stephen23 2020 年 3 月 12 日

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

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2020 年 3 月 12 日

編集済み:

2020 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by