I need help using the feval command

1 回表示 (過去 30 日間)
Chris
Chris 2013 年 6 月 19 日
Write a function to define fx=@(x) 1/((x-.3)^2+.01)+1/((x-.9)^2+.04)-6 a) Plot this function using fplot command between 0 and 2. b) Determine zero of this function in the above interval. c) Determine for which x the function will be maximum in the above interval. d) What is the maximum value of the function f(x). (hint: look for feval command) I got most of it but I am lost on using the feval command.

採用された回答

Youssef  Khmou
Youssef Khmou 2013 年 6 月 20 日
編集済み: Youssef Khmou 2013 年 6 月 20 日
hi, To analyze your function, you must add the element wise operator to avoid the error of ' Matrix must be square', here is a version :
fx=@(x) 1./((x-.3).^2+.01)+1./((x-.9).^2+.04)-6
fplot(fx,[0 2])
grid on
z=fzero(fx,[0 2]);
In the next, i propose to use a predefined linear vector x, then apply the feval command on it :
N=1000; % Resolution
x=linspace(0,2,N);
[a,b]=max(feval(fx,x));
a represents the maximum value which is : 96.5014, to get the value of x, which is related to a sample rate of the vector x, proceed as the following :
Ts=2/N; % Inverse of the sample rate .
b=b*Ts;
Summary :
The function passes through the x axis at x=1.2995, has maximum value of M=96.5041 that corresponds to x=0.3020 .
  1 件のコメント
Chris
Chris 2013 年 6 月 20 日
Thank you so much. Matlab is so confusing.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by