필터 지우기
필터 지우기

Nested function global variable

조회 수: 8 (최근 30일)
Robbie Peck
Robbie Peck 2015년 10월 15일
편집: Thorsten 2015년 10월 15일
function T = fun(theta)
global m
m = theta^2;
T = quad(@fun2,0,1)
end
function out = fun2(t)
out=( (1-m*t^2)*(1-t^2) );
end
I have the two functions above. When I call for fun, it does not seem to be working. I am new to Matlab so it would be greatly appreciated if someone could help my understanding. Thanks

채택된 답변

Thorsten
Thorsten 2015년 10월 15일
편집: Thorsten 2015년 10월 15일
Add global m to your fun2; I also used point-wise multiplication and exponentiation to make it work.
function T = fun(theta)
global m
m = theta^2;
T = quad(@fun2,0,1)
end
function out = fun2(t)
global m
out=( (1-m*t.^2).*(1-t.^2) );
end
Alternatively, you could define fun2 as an anonymous function; note that here fun2 is already a function handle, so you have to pass with without the @ to quad:
function T = fun(theta)
global m
m = theta^2;
fun2 = @(t) (1-m*t.^2).*(1-t.^2)
T = quad(fun2,0,1)
end
  댓글 수: 1
Robbie Peck
Robbie Peck 2015년 10월 15일
Thank you- It's the point wise stuff I'm not used to. I'm used to R!

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

추가 답변 (1개)

Julia
Julia 2015년 10월 15일

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by