필터 지우기
필터 지우기

How can I fix this error?

조회 수: 1 (최근 30일)
Wenchen Liu
Wenchen Liu 2022년 12월 5일
댓글: Torsten 2022년 12월 5일
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?

답변 (1개)

David Hill
David Hill 2022년 12월 5일
f = @(x)4./(1+x.^2)
f = function_handle with value:
@(x)4./(1+x.^2)
a = 0;
b = 1;
F = @(x)-8*x./(1+x.^2).^2 % antiderivative of f
F = function_handle with value:
@(x)-8*x./(1+x.^2).^2
ref = F(b) - F(a);
n = 2;
x = linspace(a,b,n+1);
h = (b-a)/n;
  댓글 수: 2
Wenchen Liu
Wenchen Liu 2022년 12월 5일
clear all, close all
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;
i have fixed the questions, but in the command it still shows:
Argument to dynamic structure reference must evaluate to a valid field name.
Error in assignment3_question2b (line 7)
F = @(x)-8*x.(1+x.^2).^2 % antiderivative of f
Error in assignment3_question2b (line 8)
ref = F(b) - F(a);
Torsten
Torsten 2022년 12월 5일
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)

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

카테고리

Help CenterFile Exchange에서 Special Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by