matlab中怎么求两曲线交点
1个回答
2017-09-14
展开全部
matlab中怎么求两曲线交点
>> x = 0:0.0025:2;
>> fy1 = @(x) 0.2*exp(-0.5)*cos(4*pi*x);
>> fy2 = @(x) 2*exp(-0.5)*cos(pi*x);
>> plot(x,fy1(x),'g',x,fy2(x),'b');
>> legend('y1','y2')
% 观察可知交点在x=0.5,x=1.5附近,用fsolve求解
>> fun = @(x) fy1(x)-fy2(x);
>> x0 = fsolve(fun,0.5);
>> x1 = fsolve(fun,1.5);
>> hold on
>> plot(x0,fy1(x0),'ro',x1,fy1(x1),'ro')
>> text(x0,fy1(x0),['(',<a href="https://www.baidu.com/s?wd=num2str&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uWIBPvPbmhRduWfsmW7h0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHT1n1Tdn16kn1TvnjR3PHfvPs" target="_blank" class="baidu-highlight">num2str</a>(x0),',',<a href="https://www.baidu.com/s?wd=num2str&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uWIBPvPbmhRduWfsmW7h0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHT1n1Tdn16kn1TvnjR3PHfvPs" target="_blank" class="baidu-highlight">num2str</a>(fy1(x0)),')'])
>> text(x1,fy1(x1),['(',<a href="https://www.baidu.com/s?wd=num2str&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uWIBPvPbmhRduWfsmW7h0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHT1n1Tdn16kn1TvnjR3PHfvPs" target="_blank" class="baidu-highlight">num2str</a>(x1),',',num2str(fy1(x1)),')'])
>> x = 0:0.0025:2;
>> fy1 = @(x) 0.2*exp(-0.5)*cos(4*pi*x);
>> fy2 = @(x) 2*exp(-0.5)*cos(pi*x);
>> plot(x,fy1(x),'g',x,fy2(x),'b');
>> legend('y1','y2')
% 观察可知交点在x=0.5,x=1.5附近,用fsolve求解
>> fun = @(x) fy1(x)-fy2(x);
>> x0 = fsolve(fun,0.5);
>> x1 = fsolve(fun,1.5);
>> hold on
>> plot(x0,fy1(x0),'ro',x1,fy1(x1),'ro')
>> text(x0,fy1(x0),['(',<a href="https://www.baidu.com/s?wd=num2str&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uWIBPvPbmhRduWfsmW7h0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHT1n1Tdn16kn1TvnjR3PHfvPs" target="_blank" class="baidu-highlight">num2str</a>(x0),',',<a href="https://www.baidu.com/s?wd=num2str&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uWIBPvPbmhRduWfsmW7h0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHT1n1Tdn16kn1TvnjR3PHfvPs" target="_blank" class="baidu-highlight">num2str</a>(fy1(x0)),')'])
>> text(x1,fy1(x1),['(',<a href="https://www.baidu.com/s?wd=num2str&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uWIBPvPbmhRduWfsmW7h0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHT1n1Tdn16kn1TvnjR3PHfvPs" target="_blank" class="baidu-highlight">num2str</a>(x1),',',num2str(fy1(x1)),')'])
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询