matlab250e3,(暂未解决)vpasolve求解范围太大则得不到结果

clear;clc;

syms x y

y=1/(2.*x^7+x^3+2)+100;

y2=x+3;

[x0,dy]=solveMono(y,[-100,0])

function [x0,y0]=solveMono(fHd,limVec)

nGrid=1000;%Search Grid;

p=0.5;%march Infactor

err=1e-12;% zero precision

dErr=1e-20;%dy precision

x0=mean(limVec);

syms X_

y(X_)=subs(fHd,X_);

yp(X_)=diff(y,X_);

y0=y(x0);yp0=yp(x0);

% y0 + yp0 + stepSign -

% y0 - yp0 - stepSign -

% y0 + yp0 - stepSign +

% y0 - yp0 + stepSign +

count=0;

stepSign=logical(y0.*yp0<0)-logical(y0.*yp0>0);

lim=limVec((stepSign-(-1))/2+1);

dy=1+err;

figure;

while abs(y0)>err && abs(dy)>err

xVec1=linspace(x0,lim,nGrid);

xVec=xVec1(1:end-1);

yVec=y(xVec);

productY=yVec(1:end-1).*yVec(2:end);

negIndex=find(productY<0);

if isempty(negIndex)

x0Last=xVec(floor(nGrid.*p));y0Last=yVec(floor(nGrid.*p));

x0=xVec(floor(nGrid.*p)+1);y0=yVec(floor(nGrid.*p)+1);

else

x0Last=xVec(negIndex(1));y0Last=yVec(negIndex(1));

x0=xVec(negIndex(1)+1);y0=yVec(negIndex(1)+1);

end

count=count+1;

dy=y0-y0Last;

fprintf('\nsolveMono():%d,%.12f,%.12f',count,x0,y0);

%     vpa([count,x0,y0])

if count==1

subplot(2,2,1);hold on;plot(x0Last,count,'o');xlabel('x_0');ylabel('count');drawnow;title('Search Contrary Sign');grid on;

subplot(2,2,3);hold on;plot(count,y0Last,'o');xlabel('count');ylabel('y_0');drawnow;grid on;

end

subplot(2,2,1);hold on;plot(x0,count,'o');xlabel('x_0');ylabel('count');drawnow;title('Search Contrary Sign');grid on;

subplot(2,2,3);hold on;plot(count,y0,'o');xlabel('count');ylabel('y_0');drawnow;grid on;

if y0*y0Last<0

if y0

xLeft=x0;xRight=x0Last;

yLeft=y0;%yRight=y0Last;

elseif y0>=y0Last

xLeft=x0Last;xRight=x0;

yLeft=y0Last;%yRight=y0;

end

while abs(yLeft)>err && abs(dy)>dErr

xVec=linspace(xLeft,xRight,nGrid);

yVec=y(xVec);

productY=yVec(1:end-1).*yVec(2:end);

negIndex=find(productY<0);

yLeftLast=yLeft;

xLeft=xVec(negIndex(1));yLeft=yVec(negIndex(1));

xRight=xVec(negIndex(1)+1);%yRight=yVec(negIndex(1)+1);

dy=yLeft-yLeftLast;

count=count+1;

fprintf('\nsolveMono():%d,%.12f,%.12f',count,xLeft,yLeft);

%             vpa([count,xLeft,yLeft])

subplot(2,2,2);hold on;plot(xLeft,count,'*');xlabel('x_0');ylabel('count');drawnow;title('Search Zero Point');grid on;

subplot(2,2,4);hold on;plot(count,yLeft,'*');xlabel('count');ylabel('y_0');drawnow;grid on;

end

x0=xLeft;y0=double(yLeft);

end

end

close(gcf)

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值