在MATLAB中已知自变量的值,怎样求函数值

如题所述

第1个回答  2017-08-07
clear all;clc;
x=-pi/2:pi/50:pi;
y=sin(x);
plot(x,y);
grid on;
fm=max(y)
id=find(y==fm);
xm=x(id)
例如
fs=3200;
x=0:1/fs:0.32-1/fs;
y=cos(2*pi*50*x);
>> c=find(y==-1)

c =

33 97 161 225 289 353 417 481 545 609 673 737 801 865 929 993

>>
那么对应的x值就是
>> x(c)

ans =

Columns 1 through 10

0.0100 0.0300 0.0500 0.0700 0.0900 0.1100 0.1300 0.1500 0.1700 0.1900

Columns 11 through 16

0.2100 0.2300 0.2500 0.2700 0.2900 0.3100

>>