matlab - 在改变一个参数的同时绘制函数
问题描述
我有一个 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 新手。谢谢
解决方案
您的问题不清楚,因为您说要绘制的变量未在代码中标识。尽管您在函数中调用它们并不重要(就像您在评论中所说的那样),但如果您的问题不清楚,那么我们必须猜测 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
推荐阅读
- sql - 有没有办法为每个“组”提取一个与同一组中的其他价格重复的记录?
- java - 对 tuple(int, string) 进行排序并将字符串值保存在字符串数组中
- xml - 在 SQL Server 2014 中使用 Transact-SQL 解析 XML 数据
- javascript - Facebook Graph Places Search API 不工作
- php - 为什么我的 PHP 套接字不能在公共网站上工作?
- c++ - 如果我在锁定互斥锁之前解锁它可以吗?
- python - 如何从 csv 文件中获取行的内容?
- templates - 如果 Json 集为空,则渲染特殊模板
- javascript - 验证最短日期 JavaScript
- react-native - 错误的 componentWillUpdate 警告