Element-By-Element Operations using Matlab

I wonder how to calculate the following sum using Element-By-Element Operations Matlab:
∑_(i=1)^4(u_i.[min(0,A_i.x-b_i )]^2)
i=1:4
u_i is a scalar
A_i is a (1,4) vector
b_i is a scalar
and
x is a (4,1) vector

 採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 25 日
編集済み: Andrei Bobrov 2013 年 11 月 25 日

0 投票

u*min(0,A*x-b).^2;

3 件のコメント

imed NASRI
imed NASRI 2013 年 11 月 25 日
編集済み: imed NASRI 2013 年 11 月 25 日
It doesn't work.
u is a (1,4) vector
A is a (4,4) matrix
x is a (4,1) vector and
b is a (4,1) vector
imed NASRI
imed NASRI 2013 年 11 月 25 日
編集済み: imed NASRI 2013 年 11 月 25 日
I want to calculate automatically this sum:
u(1)*[min(0,A(1,:)*x-b(1))]^2+u(2)*[min(0,A(2,:)*x-b(2))]^2+u(3)*[min(0,A(3,:)*x-b(3))]^2+u(4)*[min(0,A(4,:)*x-b(4))]^2
Andrei Bobrov
Andrei Bobrov 2013 年 11 月 25 日
I corrected

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

その他の回答 (1 件)

Biswajit M
Biswajit M 2013 年 11 月 25 日

0 投票

hope this helps:
u(1)*(min(0,min(A(1,:)))*x-b(1)) .^2+u(2)*(min(0,min(A(2,:)))*x-b(2)) .^2+u(3)*(min(0,min(A(3,:)))*x-b(3)) .^2+u(4)*(min(0,min(A(4,:)))*x-b(4)) .^2
I tried it this way :
clear all; clc
u=[1,2,3,4]; A=[1,2,3,4;5,6,7,8;1,2,3,4;5,6,7,8]; x=[5;6;7;8]; b=[4;5;6;7]; min(0,min(A(1,:)))
u(1)*(min(0,min(A(1,:)))*x-b(1)) .^2+u(2)*(min(0,min(A(2,:)))*x-b(2)) .^2+u(3)*(min(0,min(A(3,:)))*x-b(3)) .^2+u(4)*(min(0,min(A(4,:)))*x-b(4)) .^2
The output comes like:
ans =
370
370
370
370

1 件のコメント

imed NASRI
imed NASRI 2013 年 11 月 25 日
編集済み: imed NASRI 2013 年 11 月 25 日
My vectors have sometimes a size (1000). In this case your équation becomes so hard to write. I Wonder if i can use a loop to calculate automatically this sum??!!!

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

カテゴリ

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

タグ

質問済み:

2013 年 11 月 25 日

編集済み:

2013 年 11 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by