Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

can someone explain me this code please?

조회 수: 3 (최근 30일)
Anonymous Learner
Anonymous Learner 2015년 5월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
clc;
clear all;
close all;
f=@(x)x.^3;
a=1;b=2;
n=1.25;
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=i.^3;
end
l=length(x);
x
y
answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))

답변 (1개)

Roger Stafford
Roger Stafford 2015년 5월 27일
This looks like a misguided attempt to use trapezoidal approximation to find the integral of y = x^3 over an interval in x. The values assigned to 'a', 'b', and 'h' are inappropriate for such an interpretation however.
Anyhow, there is a much easier method for such an integral using calculus:
answer = (b^4-a^4)/4;
Why do numerical approximation when such an easy formula exists with the exact answer?

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by