How to include the integral of a certain function in another .m file function?

5 ビュー (過去 30 日間)
Matthew Worker
Matthew Worker 2016 年 11 月 17 日
編集済み: John Kelly 2017 年 2 月 15 日
I have fun1.m file that I want to include in it the integral of cos(x) provided that the integral of cos(x) has to be in a different file too e.g. fun2.m
fun1()
fun2()

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 17 日
function r = fun1(x)
y1 = fun2(x); %numeric using all x values
y2 = fun3(x); %symbolic using first and last x values
r = y1(x) - y2(x);
function result = fun2(x)
result = trapz( x, cos(x) ); %one form of numeric integral
function result = fun3(x)
syms X
xint = int(cos(X), X, x(1), x(end)); %symbolic integral between endpoints
result = double(xint);

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by