x=[1:1:10];
a=2;
b=4;
c=6;
for i=1:length(x)
A=a*b/x(i);
B=c+A(i)/b;
D=a+b;
E=1-2*c;
MAT=[B(i);D;E];
M=sqrt([MAT])
end
I am not able to matrix corresponding to 10 values of x.
plz help
thanks

댓글 수: 1

This line will create a scaler value for A
A=a*b/x(i);
On the following line you are trying to index a scaler value
B=c+A(i)/b;

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

 채택된 답변

VBBV
VBBV 2021년 4월 11일

1 개 추천

clear
x=[1:1:10];
a=2;
b=4;
c=6;
for i=1:length(x)
A(i)=a*b/x(i);
B(i)=c+A(i)/b;
D=a+b;
E=1-2*c;
MAT(i,:)=[B(i);D;E];
end
M=sqrt(abs(MAT))

댓글 수: 2

VBBV
VBBV 2021년 4월 11일
In my solution, the Matrix MAT is not 3 x 1. It is 10 x 3 for which sqrt is possible and same as what you would get if you perform MAT.^(1/2) element wise operation.
ASHA RANI
ASHA RANI 2021년 4월 12일
VBBV, thanks
Its works .

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

추가 답변 (1개)

Jan
Jan 2021년 4월 11일

0 개 추천

Maybe you want:
for i = 1:length(x)
A(i) = a * b / x(i);
B(i) = c + A(i) / b;
D(i) = a + b;
E(i) = 1 - 2 * c;
...

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2021년 4월 11일

댓글:

2021년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by