【问题标题】:Graphing functions while varying one parameter在改变一个参数时绘制函数
【发布时间】:2020-04-06 19:47:58
【问题描述】:

我有一个 Matlab 函数,我想在将某个参数从 100 更改为 1000 的同时绘制它 它是这样的: [c, errorrange, i] = function [g1, g2, x]; 我想在改变 x 的同时绘制 x 和 c

函数本身 ......

  function [root,e, i]=func(xl,xu,e_stopping, z)
    if ((((xl^4)/(20*z)-(3*z^2*xl^2)/50)*((xu^4)/(20*z)-(3*z^2*xu^2)/50)) > 0) 
        error('the intials wont work');
    end
    root = z/2+z*2;
    e = 2;
    i = 2;
    end

.......

我想到了这样的事情:

...

for i = 100: 1000
[c, error] = fund(1000, 2000,0, i);
A(i) = c;
end
for i = 1: 99
A(i) = 0;
end
plot(A); 

... 但它不起作用;抱歉,如果我的问题不好,我是 Matlab 新手。 谢谢你

【问题讨论】:

    标签: matlab matlab-figure matlab-guide


    【解决方案1】:

    您的问题不清楚,因为您说要绘制的变量未在代码中标识。尽管在函数中调用它们并不重要(就像您在 cmets 中所说的那样),但如果您的问题不清楚,那么我们必须猜测 i=x 或 A=x 或任何您想要的.

    我仍然不确定你想要绘制什么,但这应该足够接近让你开始。基本上,看起来您不需要任何 for 循环,您只需将向量输入传递给您的函数。

    A = 1:1:100; % create this vector however you need
    [c, error] = func(1000, 2000, 0, A);
    
    plot(A, c)
    xlabel('my input A', 'FontSize', 10)
    ylabel('my function output c', 'FontSize', 10)
    title("my graph", 'FontSize', 12)
    
    
    
    function [root, e, i] = func(xl, xu, e_stopping, z)
        root = z/2 + z*2;
        e = 2;
        i = 2;
    end
    

    【讨论】:

    • 非常感谢您的回复。
    • 它告诉我“矩阵尺寸不一致”。另外,我的函数给出了三个答案,而您只使用一个变量 - 这怎么可能?
    • 你没有提供函数,所以我做了一个作为例子。在您的帖子中,您的函数给出 2 个答案并需要 3 个输入(答案/输出在左侧,括号内;输入在右侧,括号内)
    • 如果您修改您的问题,为您的功能和输入添加一个“简化”版本(即易于重现),它会更容易提供帮助
    • x = 100:5:1000 [root, e, itr] = func(0,5,0, x);错误使用/矩阵尺寸必须一致。那是错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    相关资源
    最近更新 更多