Element-By-Element Operations using Matlab
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
imed NASRI
le 25 Nov 2013
Modifié(e) : imed NASRI
le 25 Nov 2013
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
0 commentaires
Réponse acceptée
Andrei Bobrov
le 25 Nov 2013
Modifié(e) : Andrei Bobrov
le 25 Nov 2013
u*min(0,A*x-b).^2;
3 commentaires
Plus de réponses (1)
Biswajit M
le 25 Nov 2013
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 commentaire
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!