# curve fitting in matlab

I have four curves for four different times as shown below in the figure. I need to draw the curve for time in between the given times e.g., I need to plot the curve for $t= 3$ and $t=10$ in matlab (this is just an example shown in below figure).

Is it possible, if so, please suggest something. A big thank you.

-
So basically you just want to plot $\sin(3t)$ and $\sin(10t)$ (perhaps in the same plot)? –  Eff Apr 9 '14 at 12:03
You can look at interpolating, but it might not work if the functions are like the sin waves in your example. You'd have to provide more context and details for any real help. It's too dependent on what the functions are to give a general answer. –  AnonSubmitter85 Apr 13 '14 at 0:44

If I interpret your question correctly, you want to plot f(t,x)=sin(t*x) for various values of t and x? Am I right? If so, the following code creates a quite extensive graph with f(t,x) evaluated for many values of t and x, but a few values of t and x are marked.

The command mesh(X,Y,Z) can make 3D plots of {X,Y,Z} data.

clear
close all

f=@(t,x)sin(t.*x);

n=101;

minT=0;
maxT=20;
minX=0;
maxX=1;

T=linspace(minT,maxT,n);
X=linspace(minX,maxX,n);

[T,X]=meshgrid(T,X);

Z=f(T,X);

% the blue mesh plot
mesh(T,X,Z,'MeshStyle','column','EdgeColor','b','FaceAlpha',.2)

xlabel t
ylabel x
zlabel z
title('z=sin(t*x)')

set(gca,'View',[50 70])

% the plot with t=[1 5 11 17] marked
k=[];
for tToFind=[1 5 11 17]
k=[k find(T==tToFind)];
end

hold on
mesh(T(k),X(k),Z(k),...
'EdgeColor','r',...
'FaceAlpha',.2,...
'MeshStyle','Column',...
'LineWidth',2)

% the plot with x=[.1 .25 .6 .8] marked
k=[];
for xToFind=[.1 .25 .6 .8]
k=[k find(X==xToFind)];
end

mesh(T(k),X(k),Z(k),...
'EdgeColor','g',...
'FaceAlpha',.2,...
'MeshStyle','Column',...
'LineWidth',2)


Please use the Rotate 3D button in the Figure window to rotate the view of the 3D plot, then you will get a better feeling for what is plotted. You might also want to maximise your Figure window. Remember to look at the axis labels, to see where the t- and x-axes are while rotating.

-