Azzera filtri
Azzera filtri

How can i fplot two functions in different intervals?

4 visualizzazioni (ultimi 30 giorni)
I have two functions, F1 and F2. function F1 is calculate in interval [a,b] and function F2 in [c,d]. How can i plot both them in one figure?

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 26 Lug 2013
Modificato: Azzi Abdelmalek il 26 Lug 2013
x1=0:0.1:10;
x2=10:0.1:20;
y1=sin(x1);
y2=cos(x2);
plotyy(x1,y1,x2,y2)
% or
x1=0:0.1:10;
x2=10:0.1:20;
y1=sin(x1);
y2=20*cos(x2);
plot(x1,y1);
ax=axes('position',get(gca,'position'),'color','none','XAxisLocation','top','YAxisLocation','right')
plot(x2,y2,'r')
set(ax,'visible','off')
ax=axes('position',get(gca,'position'),'color','none','XAxisLocation','top','YAxisLocation','right')
set(ax,'xcolor','r','ycolor','r','xlim',[min(x2) max(x2)],'ylim',[min(y2) max(y2)])
  1 Commento
fatemeh
fatemeh il 27 Lug 2013
if true
% code
end
My program is Below about calculation of spline function. I want to fplot spline function (l) in two interval (100,250), (250,400). I could not execute your order. Please guide me.
Regards
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
syms z
x=[100 250 400];
f=[-.0486 -0.085 -0.259];
n=length(x);
for i=1:n-1
h(i+1)=x(i+1)-x(i);
end
%%%%%%%%%%%%%%%%%%%spline darage 3
for j=1:n-1
c=((f(j+1)-f(j))/h(j+1))-(((2*m(j,1)+m(j+1,1))/6)*h(j+1));
d=m(j,1)/2;
e=(m(j+1,1)-m(j,1))/(6*h(j+1));
s=f(j)+c*(z-x(j))+d*(z-x(j))^2+e*(z-x(j))^3;
% fprintf('the polinomial between %d & %d is:',x(j),x(j+1));
pretty(s)
l=char(s);
fplot(l,[x(j),x(j+1)],'*')
ax=axes('position',get(gca,'position'),'color','none','XAxisLocation','top','YAxisLocation','right')
fplot(l,[x(j),x(j+1)],'*')
set(ax,'visible','off')
ax=axes('position',get(gca,'position'),'color','none','XAxisLocation','top','YAxisLocation','right')
set(ax,'xcolor','r','ycolor','r','xlim',[min(x(j)) max(x(j+1))],'ylim',[min(l) max(l)])
end

Accedi per commentare.

Più risposte (1)

Jan
Jan il 26 Lug 2013
Modificato: Jan il 26 Lug 2013
What about:
axes('NextPlot', 'add'); % Alternative: hold all
plot(1:10, rand(1, 10), 'r');
plot(6:15, rand(1, 10), 'b');
  1 Commento
fatemeh
fatemeh il 27 Lug 2013
if true
% code
end
My program is Below about calculation of spline function. I want to fplot spline function (l) in two interval (100,250), (250,400). I could not execute your order. Please guide me.
Regards
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
syms z
x=[100 250 400];
f=[-.0486 -0.085 -0.259];
n=length(x);
for i=1:n-1
h(i+1)=x(i+1)-x(i);
end
%%%%%%%%%%%%%%%%%%%spline darage 3
for j=1:n-1
c=((f(j+1)-f(j))/h(j+1))-(((2*m(j,1)+m(j+1,1))/6)*h(j+1));
d=m(j,1)/2;
e=(m(j+1,1)-m(j,1))/(6*h(j+1));
s=f(j)+c*(z-x(j))+d*(z-x(j))^2+e*(z-x(j))^3;
% fprintf('the polinomial between %d & %d is:',x(j),x(j+1));
pretty(s)
l=char(s);
fplot(l,[x(j),x(j+1)],'*')
ax=axes('position',get(gca,'position'),'color','none','XAxisLocation','top','YAxisLocation','right')
fplot(l,[x(j),x(j+1)],'*')
set(ax,'visible','off')
ax=axes('position',get(gca,'position'),'color','none','XAxisLocation','top','YAxisLocation','right')
set(ax,'xcolor','r','ycolor','r','xlim',[min(x(j)) max(x(j+1))],'ylim',[min(l) max(l)])
end

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by