【问题标题】:matlab find intersection of two curvesmatlab求两条曲线的交点
【发布时间】:2018-01-28 01:11:09
【问题描述】:

我需要在 Matlab 中找到二极管的电流,有 2 个方程,但我找不到交点。此函数中没有真正的交点,但我需要找到最接近的可能当前值(点后需要 3 个正确数字)当前代码在这里;

clc;
close all;
clear all;
a=27;% tempature in celcius
b=2*(10.^(-14));%saturation current
q=1.6e-19;%electron charge
k=1.38e-23;%boltzman's constant
t=a+273;%temp in kelvin
v=-0.2:0.00001:0.715;%source voltage
i=b*(exp(q*v/(k*t))-1);%diode i-v characteristic formula
i2=(5-v)/1000;%kirchoff's voltage law formula
plot (v,i,v,i2)    
xlabel('Voltage -->')
ylabel('Current -->')
grid on;
axis([0.2 2 0 0.03])`

我需要找到最接近的 ii2 值。因为我要反复做,所以我必须制定它。

【问题讨论】:

标签: matlab math matlab-figure


【解决方案1】:

这个解决方案让我们使用min 函数,该函数确定向量的最小值以及该最小值出现的索引:

[difference,index] = min(abs(i-i2));
disp(v(index));   % point where both curves are closest
disp(difference); % how close they are at that point

【讨论】:

    【解决方案2】:

    您可以定义两个不同的函数句柄,而不是通过直接将计算应用到给定范围 v 来以数值方式评估您的 ii2 曲线:

    i_fun = @(v) b .* (exp((q .* v) / (k * t)) - 1);
    i2_fun = @(v) (5 - v) / 1000;
    

    完成后,您可以按如下方式计算曲线值:

    v = -0.2:0.00001:0.715;
    i = i_fun(v);
    i2 = i2_fun(v);
    

    这将允许您使用fsolve function 更轻松地检测交叉点:

    diff_fun = @(v) i2_fun(v) - i_fun(v);
    int_x = fzero(diff_fun,3);
    int_y = feval(i_fun,int_x);
    

    完整的工作示例:

    clc;
    close all;
    clear all;
    
    a = 27;
    b = 2*(10.^(-14));
    q = 1.6e-19;
    k = 1.38e-23;
    t = a + 273;
    
    i_fun = @(v) b .* (exp((q .* v) / (k * t)) - 1);
    i2_fun = @(v) (5 - v) / 1000;
    diff_fun = @(v) i2_fun(v) - i_fun(v);
    
    v = -0.2:0.00001:0.715;%source voltage
    i = i_fun(v);
    i2 = i2_fun(v);
    int_x = fzero(diff_fun,3);
    int_y = feval(i_fun,int_x);
    
    plot(v,i,v,i2);
    hold on;
    plot(int_x,int_y,'ob');
    hold off;
    

    输出:

    【讨论】:

    • 如果曲线确实相交,这可能是最好的解决方案,但应该进行最终验证以找出它们的距离最小的地方,以防万一。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多