필터 지우기
필터 지우기

how to tabulate results of function in matlab

조회 수: 6 (최근 30일)
fourough
fourough 2013년 3월 15일
답변: Dianne Dampil 2014년 2월 25일
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

채택된 답변

fourough
fourough 2013년 3월 15일
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)
  댓글 수: 1
Image Analyst
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
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

Dianne Dampil
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

카테고리

Help CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by