Effacer les filtres
Effacer les filtres

how to tabulate results of function in matlab

6 vues (au cours des 30 derniers jours)
fourough
fourough le 15 Mar 2013
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

Réponse acceptée

fourough
fourough le 15 Mar 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 commentaire
Image Analyst
Image Analyst le 16 Mar 2013
See the addition to the code I made that will print out the values in a table.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 15 Mar 2013
Modifié(e) : Image Analyst le 16 Mar 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 le 25 Fév 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

Catégories

En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by