thanks for your help,but my problem is to show the values of t and sin(t) in table,such that it enables me to retrieve any value of table afterwards...like what we were doing before calculators become trendy(working with sinuns tables in hard copy, during exam)
how to tabulate results of function in matlab
4 次查看(过去 30 天)
显示 更早的评论
I have a program which I need to tabulate sin(t) function in t=[-3,3] and plot it in 50 points in this interval.My code is
function inversehw3a
disp(' t sin(t)')
for x=-3:6/50:3
y=sin(x);
A=[x,y];
disp(A);
end
x=-3:6/50:3;
plot(x,sin(x)),grid on
0 个评论
采纳的回答
fourough
2013-3-15
1 个评论
Image Analyst
2013-3-16
See the addition to the code I made that will print out the values in a table.
更多回答(2 个)
Image Analyst
2013-3-15
编辑:Image Analyst
2013-3-16
I probably would have used linspace() to avoid having to figure out what the step size needs to be - you just specify the 50 directly and it does it for you. I'd also vectorize the code like this:
x = linspace(-3, 3, 50);
y = sin(x);
% Plot it.
plot(x, y, 'bo-', 'LineWidth', 2);
grid on;
% Make labels:
fontSize = 30;
title('y = sin(x)', 'FontSize', fontSize);
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
EDIT
% Print out coordinates:
for k = 1 : length(x)
fprintf('(x(%d), y(%d)) = (%.4f, %.4f)\n',...
k, k, x(k), y(k));
end
0 个评论
Dianne Dampil
2014-2-25
how can i tabulate this?
%Modified eler method %mod.m
syms x y; f = input('Enter the slope : '); x0 = input('Enter the initial value of x:'); y0 = input('Enter the initial value of y: '); h = input('Enter the value of h:'); x1 = x0; y1 = y0;
for i=1:25 y1 = y0 + h * subs(f,{x,y},{(x0+1/2*h),(y0+1/2*h*subs(f,{x,y},{x0,y0}))}) x0 = x0 + h y0 = y1; end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!