How to plot these functions?

3 次查看(过去 30 天)
Hello, everyone.
I am trying to plot this function but I can not do it. I got some errors, this is the function that I have to plot. Please someone help me.
By the way, thanks.
Here you have my code:
And the command window responses:

采纳的回答

Image Analyst
Image Analyst 2015-10-26
I hope this isn't your homework (or else it would be unethical for you to turn this code in). You can do this:
clc; % Clear the command window.
close all;
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Create x and y
x = linspace(0.3, 0.7, 500);
y = linspace(0.3, 0.7, 500);
% Create image
rows = length(y);
columns = length(x);
z = zeros(rows, columns);
for row = 1 : rows
thisY = y(row);
for col = 1 : columns
thisX = x(col);
if thisX > 0.3 && thisX < 0.5 && thisY > 0.3 && thisY < 0.5
z(row, col) = (10*thisX-3)*(10*thisY-3)/4;
elseif thisX > 0.3 && thisX < 0.5 && thisY > 0.5 && thisY < 0.7
z(row, col) = (10*thisX-3)*(7-10*thisY)/4;
elseif thisX > 0.5 && thisX < 0.7 && thisY > 0.3 && thisY < 0.5
z(row, col) = (7-10*thisX)*(10*thisY-3)/4;
elseif thisX > 0.5 && thisY > 0.5
z(row, col) = (7-10*thisX)*(7-10*thisY)/4;
end
end
end
imshow(z, [], 'XData', x, 'YData', y);
colorbar;
colormap(parula(256));
axis on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
  3 个评论
Image Analyst
Image Analyst 2015-10-26
Well, if it's homework, you're supposed to turn in your own work, not just ask someone else to do it for you and turn in their work. The code was very very simple and basic. For further reading: http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab
Luis Raves
Luis Raves 2015-10-26
编辑:Luis Raves 2015-10-26
Well, it's homework, I was trying to do it for a long time without results, and I was looking for help, your code is going to help me with other Implications that I have to code. This is my first question here in the forum but for the next times I'm gping to make it better. If I bothered you I ask you an apology. Thank you for your attention. :D

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2015-10-26
I don't think you'd plot it. Since x and y both vary, I think you'd create an image and use imshow() to display the values. Or use surf() if you want a 2.5-D perspective view.
  1 个评论
Luis Raves
Luis Raves 2015-10-26
Thanks to answer. I refreshed the question and I put the code in this time, can you check it?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by