parse error at x: usage might be invalid matlab syntax

Hello guys, i was trying to use a code that can solve simpsons 1/3 rule for integrating functions and it was working on a fucntion
with 1 variable. So i tried changing the function and used another one. the thing is that im having an error when running this code
it says parse error at x: usage might be invalid matlab syntax. The error is happening at the first line. The x that has the error
is the 25x. There is another error that says brackets instead of parentheses. Im new to matlab and i dont know what to do.
N.B: the matlab im using is the online matlab
f = @(x) 0.2 + 25x - 200x^(2) + 674=5x^(3) - 900x^(4) + 400x^(5);
a = 0;
b = 0.8;
n = 2;
h = (b-a)/n;
s = f(a)+f(b);
for i = 1:2:n-1
s = s + 4*f(a+i*h);
end
for i = 2:2:n-2
s = s + 2*f(a+i*h);
end
i = h/3 * s;

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 1일
f = @(x) 0.2 + 25*x - 200*x^(2) + 674==5*x^(3) - 900*x^(4) + 400*x^(5);

댓글 수: 1

I would be surprised if the result is not zero. The result of any comparison is 0 for false and 1 if true, and considering floating point operations, it is most likely that you will not find any locations where the left side of your comparison is exactly equal to the right side. There are only 5 total points (including complex) where the comparison is mathematically equal and you are probably not going to find them.

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

카테고리

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

제품

릴리스

R2021a

태그

질문:

2021년 5월 1일

댓글:

2021년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by