필터 지우기
필터 지우기

Function function/ passing function/ varargin help?

조회 수: 1 (최근 30일)
Gabrielle Bartolome
Gabrielle Bartolome 2020년 10월 24일
댓글: Stephen23 2020년 10월 26일
Develop a function function M-file that returns the difference between the passed function's maximum and minimum value given a range of the independent variable. In addition, have the function generate a plot of the function for the range. Test it for the following cases:
f(t) = a*exp^(-b*t)*sin(t-c) from t = 0 to 6*pi
1. a = 8, b = 0.25, c = 2 below is what I have so far. I keep getting an error. I don't know what I am doing wrong. .I would appreciate any help that you could provide. Thank you.
%input:
% a = lower bound of range
% b = upper bound of range
% n = number of intervals
%output:
% fdiff = difference between max and minimum of a function
function fdiff = funcdiff(f, a, b, n, varargin)
x = linspace(a,b,n);
y = f(x, varargin{:});
fdiff = max(y) - min(y);
fplot(f, [a b], varargin{:})
end
% clear clc
% diff = @(t) a*exp^(-b*t)*sin(t-c);
% funcdiff(diff, 0, 6*pi, 180, 8, 0.25, 2)

답변 (1개)

KSSV
KSSV 2020년 10월 24일
편집: KSSV 2020년 10월 24일
a = 8 ;
b = 0.25 ;
c = 2 ;
n = 180 ;
f = @(t) a*exp(-b*t).*sin(t-c);
t = linspace(a,b,n);
y = f(t);
fdiff = max(y) - min(y);
plot(t,y)
  댓글 수: 2
Gabrielle Bartolome
Gabrielle Bartolome 2020년 10월 24일
I am not sure I really understand the code you placed. It seems to work by itself but not as a funciton function and it doesn't use varargin.
Cole Fontana
Cole Fontana 2020년 10월 26일
편집: Cole Fontana 2020년 10월 26일
Don't worry I'm just as stuck as you are lol
Professor Huang said that we can't use fplot when using varagin.

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

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by