Borrar filtros
Borrar filtros

how to tabulate results of function in matlab

6 visualizaciones (últimos 30 días)
fourough
fourough el 15 de Mzo. de 2013
Respondida: Dianne Dampil el 25 de Feb. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 15 de Mzo. de 2013
Editada: Image Analyst el 16 de Mzo. de 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 el 25 de Feb. de 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

Categorías

Más información sobre Formula Manipulation and Simplification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by