getting error creating coefficient matrix for cramers rule

I am implementing Cramer's Rule into MATLAB and I am stuck on the coefficient matrix part as it gives me an error
% for size of matrix
n=input('');
% co-efficient matrix
coef=zeros([n n]);
and then I get an error stating that I need real integers for the zeros function
Does anyone know how to fix this? Thanks in advance.

댓글 수: 1

Matt J
Matt J 2018년 12월 11일
편집: Matt J 2018년 12월 11일
Works fine for me, as long as a positive integer is entered, e.g.,
>> % for size of matrix
n=input('');
% co-efficient matrix
coef=zeros([n n]);
5
>> coef
coef =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

댓글을 달려면 로그인하십시오.

답변 (1개)

Koundinya
Koundinya 2018년 12월 14일
The zeros function takes array dimensions as input and returns an array of zeros.
% co-efficient matrix
coef=zeros([n n]);
Here coef would be an array of size nxn with all elements equal to zero.The dimensions of an array need to be integers (array dimesion can be 0 as well). The error you get is mostly because you're inputting a non-integer value for n.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

태그

질문:

RB
2018년 12월 11일

답변:

2018년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by