Getting Error: Unexpected MATLAB expression.

Question: Use Newton's method to nd three roots of x^3 - 5x + 1 = 0 accurate to within 10^-14.
My Matlab Code:
format long
x=0.5
for I = 1:10
x=x-((x.^3)-5.x+1)/(3.(x.^2)-5),
end
x=x-((x.^3)-5.x+1)/(3.(x.^2)-5),
|
Error: Unexpected MATLAB expression.
Problem: I am getting the aforementioned error and therefore, cannot find roots of the given equation in the question. Please can you find the problem and help me out? I am new to Matlab and I am learning this software. Thanks a lot! Appreciate it. :)
MATLAB Version: MATLAB R2013a

 채택된 답변

Star Strider
Star Strider 2014년 4월 18일
편집: Star Strider 2014년 4월 18일

2 개 추천

Change it to:
x=x-((x.^3)-5.*x+1)./(3.*(x.^2)-5);
It’s missing two multiplication asterisks and a dot before the division sign.

댓글 수: 4

Image Analyst
Image Analyst 2014년 4월 19일
The dot before the / is actually not needed since the denominator is a scalar, not an array, though it does not hurt to have it.
Star Strider
Star Strider 2014년 4월 19일
편집: Star Strider 2014년 4월 19일
I agree. In all functions and most of my Answers, I vectorise everything, unless I know the intent are matrix operations.
John
John 2014년 4월 20일
Thanks Star Strider and Image Analyst! It worked. :)
Star Strider
Star Strider 2014년 4월 20일
My (our) pleasure!

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

추가 답변 (1개)

M SEETHA
M SEETHA 2022년 9월 14일

0 개 추천

IE11=(P*Ie)*((alpha*P^(-neta))*(M^2/2)+(beta*P^(-neta))*(Pr+(xi-1)*alpha*P^(-neta)/B)*(M^2/2)-(t^2/2B^2)*(B^2*e^(-B*tp)+(1-e^(-B*M))));
THIS SHOWS UNEXPECTED MATLAB EXPRESSION KINDLY HELP ME

댓글 수: 1

(t^2/2B^2) is missing an operation between the 2 and the B
I would suggest to you that the e^ parts are confusing. People are going to wonder why you named a variable e that is not the base of natural logarithms and raise it to a power. We know that it is not the base of the natural logarithms because if it were you would have coded exp() instead. Use a different variable name for whatever your e is, such as "emissivity" so readers do not get confused thinking it is an exp() operation when it is not.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2014년 4월 18일

댓글:

2022년 9월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by