フィルターのクリア

can any one explain this line of the code.

1 回表示 (過去 30 日間)
sadiqa ilyas
sadiqa ilyas 2019 年 10 月 11 日
コメント済み: sadiqa ilyas 2019 年 10 月 12 日
Data=[-1 -0.5 1 2; -4 -3 2 3];
m=2.5; % slope is kept constant
c=-10:0.1:10; % different values for intercept c to plot the cost
Cost=zeros(1,length(c));
for i=1:length(c)
Cost(i)=(1/4)*sum( (Data(2,:)'-(m*Data(1,:)'+c(i))).^2);
end
The line in side for loop.
Data(2,:)=[ -4,-3 2 3]'
m*Data(1,:)=2.5*[-1 -0.5 1 2]'
c(1)=-10
How can we add m*Data(1,:)+(-10)

採用された回答

Bob Thompson
Bob Thompson 2019 年 10 月 11 日
Per matrix math rules, when you add a single value to a matrix, that operation is applied to all values of the matrix individually.
>> Data(1,:)
-1 -0.5 1 2
>> m*Data(1,:)
-2.5 -1.25 2.5 5
>> m*Data(1,:)
-12.5 -11.25 -7.5 -5
  1 件のコメント
sadiqa ilyas
sadiqa ilyas 2019 年 10 月 12 日
Thank u

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by