如何计算scilab中的区域并通过算法找到交叉点

问题描述 投票:0回答:1

此代码表示函数g的图,其中包含两条水平线和一条垂直线:

function y = g(x)
    if x < 5 | 50 < x then
        error("Out of range");
    elseif x <= 11 then
        y = -59.535905 + 24.763399 * x - 3.135727 * x^2 + 0.1288967 * x^3;
        return;
    elseif x <= 12 then
        y = 1023.4465 - 270.59543 * x + 23.715076 * x^2 - 0.684764 * x^3;
        return;
    elseif x <= 17 then
        y = -307.31448 + 62.094807 *x - 4.0091108 * x^2 + 0.0853523 * x^3;
        return;
    else
        y = 161.42601 - 20.624104 * x + 0.8567075 * x^2 - 0.0100559 * x^3;
    end
endfunction 

**//this represents the vertical line**    
a=linspace(45,45,60)
b=linspace(0,70,60)
plot(a,b,style='r')

**//this represents the first horizontal line**    
a=linspace(0,60,60)
b=linspace(30,30,60)
plot(a,b,style='g')

//this represents the second horizontal line    
a=linspace(0,60,60)
b=linspace(40,40,60)
plot(a,b,style='g')

//this is the graph of function "g"
t = [5:50];
plot(t, feval(t, g));

// the  part of code  is for to find the solution of fsolve
//plot(t, feval(t, g)-30);
//plot(t, feval(t, g)-60);

//deff('[y] = g2(x)', 'y = g(x)-30');
//deff('[y] = g3(x)', 'y = g(x)-40');

问题是我想找到曲线和三条线之间的四个交点并计算有色表面。我怎么能在Scilab中丰富这个区域,因为我用油漆来更好地解释这个数字。并欢迎任何帮助。

enter image description here

scilab integral
1个回答
1
投票

你只需要在x = 45和x = 50之间整合max(0,min(g(x),40)-30)

integrate('max(0,min(g(x),40)-30)','x',45,50)

在测试之前,请将g函数的第一个测试更改为if 50 < x then(目前integrate中存在一个错误,无论集成域如何,都会调用函数与1作为参数进行集成)

© www.soinside.com 2019 - 2024. All rights reserved.