How can I fix this error?
    5 views (last 30 days)
  
       Show older comments
    
I had a code like this:
clear all, close all 
f = @(x)(4/(1+x^2)); 
a = 0;
b = 1;
F = @(x)(-8x/((1+x^2)^2)); % antiderivative of f
ref = F(b) - F(a);
n = 2; 
x = linspace(a,b,n+1); 
h = (b-a)/n; 
then in the command part, it shows: 
File: assignment3_question2b.m Line: 7 Column: 12
Invalid expression. Check for missing multiplication operator, missing or unbalanced
delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
How can i fix this?

0 Comments
Answers (1)
  David Hill
      
      
 on 5 Dec 2022
        f = @(x)4./(1+x.^2) 
a = 0;
b = 1;
F = @(x)-8*x./(1+x.^2).^2 % antiderivative of f
ref = F(b) - F(a);
n = 2; 
x = linspace(a,b,n+1); 
h = (b-a)/n; 
2 Comments
  Torsten
      
      
 on 5 Dec 2022
				F = @(x)-8*x.*(1+x.^2).^2; % antiderivative of f
instead of
F = @(x)-8*x.(1+x.^2).^2; % antiderivative of f
But the antiderivative of f is of course
F = @(x) 4*atan(x)
See Also
Categories
				Find more on Linear Algebra 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!

