curve fitting in matlab

498 Views Asked by At

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.$\sin(xt)$ vs $x$ where $x=[0,\pi/2]$ at different time $t$

1

There are 1 best solutions below

0
On

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)

Plot generated by code

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.