Filter löschen
Filter löschen

how to tabulate results of function in matlab

6 Ansichten (letzte 30 Tage)
fourough
fourough am 15 Mär. 2013
Beantwortet: Dianne Dampil am 25 Feb. 2014
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

Akzeptierte Antwort

fourough
fourough am 15 Mär. 2013
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 Kommentar
Image Analyst
Image Analyst am 16 Mär. 2013
See the addition to the code I made that will print out the values in a table.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 15 Mär. 2013
Bearbeitet: Image Analyst am 16 Mär. 2013
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 am 25 Feb. 2014
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

Kategorien

Mehr zu Formula Manipulation and Simplification finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by