简体   繁体   English

MATLAB:如何用矩阵绘制函数?

[英]MATLAB: how to plot a function with a matrix?

For an exercise at school, I'm trying to plot a function where the variable is a matrix. 为了在学校进行练习,我正在尝试绘制一个变量为矩阵的函数。
The function is very simple: y=x^4 函数非常简单:y = x ^ 4
The matrix, x, is 0:0.01:20 so it has a range from 0 to 20, and there are 2000 between them. 矩阵x为0:0.01:20,因此范围为0到20,并且之间有2000。
My problem is, the scale of the x-axis is 0-2000, and not 0-20 as i'd suppose it to be. 我的问题是,x轴的比例是0-2000,而不是我想的是0-20。
According to the current graph: 1000^4=10000, while it should be: 10^4=10000. 根据当前图形:1000 ^ 4 = 10000,而应该是:10 ^ 4 = 10000。
What am I doing wrong? 我究竟做错了什么?

If I understand your question correctly, this is how it should be done. 如果我正确理解了您的问题,那么应该怎么做。 To limit the range of the x-axis and y-axis: use these commands 要限制x轴和y轴的范围:请使用以下命令

ylim([minimumvalue maxvalue]);
xlim([minimumvalue maxvalue]);

Here is the answer to your question: 这是您问题的答案:

x =  0:0.01:20 ;
y =x.^4;

% plot function

plot(x,y);
title('My function')
xlabel('X-axis range')
xlim([0 20]) ![OUTPUT][1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM