parse error at x: usage might be invalid matlab syntax

18 visualizaciones (últimos 30 días)
saliba Saliba Majdalany
saliba Saliba Majdalany el 1 de Mayo de 2021
Comentada: Walter Roberson el 1 de Mayo de 2021
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;

Respuestas (1)

Walter Roberson
Walter Roberson el 1 de Mayo de 2021
f = @(x) 0.2 + 25*x - 200*x^(2) + 674==5*x^(3) - 900*x^(4) + 400*x^(5);
  1 comentario
Walter Roberson
Walter Roberson el 1 de Mayo de 2021
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by