I can't find solution of sinusoidal function's by numerical methods
Show older comments
I tried to write a code for a rectangle method(integral). Actually i saw same problem with other numerical methods too.
My problem is occur when i write a function like f = sin(x), sin(x^2) or x + sin(x^2) etc. (and i wrote a=0 and b = pi)
This code solves equations which doesn't have a trigonometric parameters.
How can i edit my code?
f =@(x) x^2;
a = 1;
b = 4;
n = 2;
h = (b-a)/n;
x(1) = f(1);
for j = 1:(n)
x(j+1) = x(1) + j*h;
c(j) = (x(j+1) + x(j)) / 2;
end
for i = 1:n
s(i) = h * f(c(i));
end
fx = sum(s);
fprintf('\n f(x) = %f',fx);
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!