필터 지우기
필터 지우기

polyfit error first two inputs must have the same number of elements.

조회 수: 7 (최근 30일)
alp onur karacay
alp onur karacay 2021년 11월 22일
답변: Walter Roberson 2021년 11월 23일
hello everyone, i have this error how can i fix it please instead of saying,write the code for it please because i am new in matlab and also my deadline is coming soon Thanks a lot for everything.
  댓글 수: 1
Image Analyst
Image Analyst 2021년 11월 22일
편집: Image Analyst 2021년 11월 22일
We can't run an image. Post text. I'm not going to rewrite all your homework for you. Make it easy to help you, not hard.
In general if you have polyfit(x, f, 4) then x must have exactly as many elements as f has. Evidently your do not.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 11월 23일
You create a vector x . Then for the function values, you compute
temp = sqrt(1/(1+x.^2))
However, here x is the entire vector, so 1+x.^2 is a vector. You then compute 1 / the vector. However, in MATLAB, the / operator is not the division operator: the / operator is the matrix division operator. When B is a matrix, A/B is similar to A * pinv(B) where the * operator I show here is the algebraic matrix multiplication operator, also known as "inner product" . The operator for doing element-by-element division is the ./ operator -- notice the period.
If you look back to where you calculated x from k values, notice that you used k(i) in your calculation, so you were working with scalars there. You do have a /n in that calculation, but when n is a scalar, pinv(n) is 1 divided by the scalar, so in the expression A/B where B is a scalar, the expression becomes equivalent to A./B -- so your code for building x from k worked out, because you selected one k value to work with at a time. But your newer loop, you did not select one x value at a time.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by