Réponse acceptée

KSSV
KSSV le 31 Mar 2017
N = 20 ;
n = 3 ;
x = linspace(0,1) ;
y = linspace(0,1) ;
z = linspace(0,1) ;
%LHS
A = zeros(3,3) ;
A(1,1) = sum(x.^2) ;
A(2,1) = sum(x.*y) ;
A(3,1) = sum(x) ;
A(1,2) = A(2,1) ;
A(2,2) = sum(y.^2) ;
A(3,2) = sum(y) ;
A(1,3) = A(3,1) ;
A(2,3) = A(3,2) ;
A(3,3) = n ;
%RHS
B = zeros(3,1) ;
B(1) = sum(x.*z) ;
B(2) = sum(y.*z) ;
B(3) = sum(z) ;

2 commentaires

Thanks but can I do this in a for loop?Just to make the code a bit general
KSSV
KSSV le 31 Mar 2017
You see that most of the elements are taking different values...so using a loop will be not handy or simple.

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 31 Mar 2017
Modifié(e) : Andrei Bobrov le 31 Mar 2017
x = (1:3)';
y = (2:4)';
z = (6:8)';
n = 5;
m = numel(x);
a = [x,y,ones(m,1)];
lhs = a.'*a;
lhs(end) = n;
rhs = a.'*z;
abc = lhs\rhs;

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by