필터 지우기
필터 지우기

How to wirte the matrix G

조회 수: 5 (최근 30일)
Chiara Lanzi
Chiara Lanzi 2019년 11월 2일
답변: Chiara Lanzi 2019년 11월 2일
HI, everyone. I found myself stack in this problem:
Suppose that you determine the masses of 100 objects by weighing the first, then weighing the first and second together, and then weighing the rest in triplets: the first, second, and third; the second, third, and fourth; and so forth.
The problem asked me to identify the model parameters and the data ( g= Gm).
I did so on my copybook, but I want to write a matlab script for this and I am struggling about how to write the G matrix in the correct way in matlab.
This is how I write G on my copybook:
[1 0 0 0 0....0]
[1 1 0 0 .....0]
[1 1 1 .......0]
[0 1 1 1 ....0]
[...................]
[0 0 0 0 ...1]
Can anyone help me?
Thank for all who will answer.

답변 (2개)

David Hill
David Hill 2019년 11월 2일
n=whatever size matrix you want.
G=eye(n)+diag(ones(1,n-1),-1)+diag(ones(1,n-2),-2);

Chiara Lanzi
Chiara Lanzi 2019년 11월 2일
Thank you for your answer.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by