José Jeremías Caballero
Servicios
de Programación en MatLab
Lima - Perú
Asesorías, Cursos y Servicios de Programación En Matlab Editor, Matlab Guide, Matlab Uicontrol a nivel: Básico, Intermedio, Avanzado. Asesorías y cursos en Metodos Numericos I, II, III y IV, Matematica Computacional I, II , Programación Lineal, Programación no lineal y Optimización.
clear all
figure(1)
figure(gcf)
syms x
y1=-3*x+18;
y2=(-3*x+27)/4;
figure(gcf)
hold on
X=solve(y1==y2);
f1=inline(y1);
f2=inline(y2);
plot(X,f1(X),'*b')
fplot(char(y1),[double(X)-5
double(X)+5],'r')
fplot(char(y2),[double(X)-5
double(X)+5],'g')
hold off
clear all
figure(2)
figure(gcf)
syms x y
e1=3*x+y-18;
e2=3*x+4*y-27;
figure(gcf)
hold
on
[X,Y]=solve(e1,e2,'x','y');
plot(X,Y,'*b')
h1=ezplot(e1,[double(X)-5 double(X)+5]);
set(h1, 'Color', 'r');
h2=ezplot(e2,[double(X)-5 double(X)+5]);
set(h2, 'Color', 'g');
grid on
hold
off
|
%%
http://www.lawebdelprogramador.com/foros/Matlab/1327174-Duda_spline.html
% Hola,
estoy haciendo un .m para obtener y dibujar las splines. Primero
%introduces
los puntos (x,y) que tu quieres.
%
% El
siguiente código te permite obtener los coeficientes para cada spline:
% De esta manera, se obtiene
%
% [ A1 B1 C1 D1; A2 B2 C2 D2;............; AN BN CN
DN]
%
% El
problema, es que aún teniendo esta matriz, no sé cómo hacer para
%representar
las funciones spline (correspondiente a cada intervalo).
%Primero
hay que introducir el vecto X e Y
clear all
X=[40 45 50
55 60 65
70];
Y=[390 340 290 250 210 180
160];
N=length(X)-1;
H=diff(X);
E=diff(Y)./H;
diagsupinf=H(2:N-1);
diagprinc=2*(H(1:N-1)+H(2:N));
U=6*diff(E);
%
restricciones del spline natural
Minicial=0;
Mfinal=0;
%
construccion de la matriz de los coeficientes para el calculo de los
%
momentos
A=diag(diagprinc)+diag(diagsupinf,1)+diag(diagsupinf,-1);
%
construccion del vector independiente para el calculo de los momentos
B=U';
B(1)=B(1)-H(1)*Minicial; B(N-1)=B(N-1)-H(N)*Mfinal;
%
resolvemos el sistema y hallamos los momentos
M=A\B;
%
añadimos los dos momentos naturales extremos y lo escribimos como vector
% fila
M=[Minicial,M',Mfinal];
%
calculo de los coeficientes del polinomio cubico i-esimo en potencias
% de (x-x_i)
for i=1:N
S(i,1)=(M(i+1)-M(i))/(6*H(i));
S(i,2)=M(i)/2;
S(i,3)=E(i)-H(i)*(M(i+1)+2*M(i))/6;
S(i,4)=Y(i);
end
%
creamos los polinomios para cada
intervalo
syms x
for i=1:N
s=0;
for j=1:size(S,2)
s=s+expand(S(i,j)*(x-X(j))^(4-j));
end
Es(i,:)=s;
end
%
Es(1)--->f1---> Intervalo X [40,45)
% Es(2)--->f2---> Intervalo X [45,50)
% Es(3)--->f3---> Intervalo X [50,55)
% Es(4)--->f4---> Intervalo X [55,60)
% Es(5)--->f5---> Intervalo X [60,65)
% Es(6)--->f6---> Intervalo X [65,70)
%dibujamos los polinomios
figure(gcf)
hold on
c='rgbcmk';
for i=1:length(X)-1
F=vectorize(inline(Es(i)));
plot(linspace(X(i),X(i+1)),F(linspace(X(i),X(i+1))),c(i),'linewidth',5)
%fplot(F,[X(i) X(i+1)],'r',);
end
plot(X,Y,'linewidth',5,'color',rand(1,3))
axis([X(1) X(end) -200 500])
grid on
hold off
|
function ode45caballero8
global a b c
fprintf('CONDICIONES: 0<a<1, b>1 , c>0\n')
fprintf('\n EJEMPLO: a=0.25 b=1.5
c=10 I=[0 1] y0=[-4 0]\n\n')
a=input('Ingrese el valor de a: ');
b=input('Ingrese el valor de b: ');
c=input('Ingrese el valor de c: ');
I=input('Ingrese el intervalo I=');
y0=input('Ingrese ondición inicial y0=');
[t,y]=ode45(@potencial_modelado1,[I(1)
I(2)],[y0(1) y0(2)]);
figure(gcf)
plot(t,y(:,1), t,y(:,2));
end
function dydt=potencial_modelado1(t,y)
global a b c
dydt=zeros(2,1);
dydt(1)=-y(1)*(y(1)-a)*(y(1)-1)-y(2); %dv/dt=
-v*(v-a)*(v-1)-w
dydt(2)=b*(y(1)-c*y(2)); %dw/dt=b*(v-c*w)
end
|
EJECUCION EN MATLAB
|
>> ode45caballero8
CONDICIONES: 0<a<1, b>1 , c>0
EJEMPLO: a=0.25
b=1.5 c=10 I=[0 1]
y0=[-4 0]
Ingrese el valor de a: 0.25
Ingrese el valor de b: 1.5
Ingrese el valor de c: 3
Ingrese el intervalo I=[0 1]
Ingrese condicion inicial y0=[1 2]
|
clear all
figure(1)
figure(gcf)
syms x
y1=2;
y2=x+1;
figure(gcf)
plot([-5 5],[ 2 2],[-5 5],[-5 5]+1)
hold on
X=solve(y1==y2);
plot(X,2,'*r')
hold off
clear all
figure(2)
figure(gcf)
syms x
y1=exp(x)-20;
fplot(char(y1),[3.5 4.5],'r')
hold on
y2=5*x+20;
fplot(char(y2),[3.5
4.5],'b')
x=fzero(char(y1-y2),[3.5
4.5]);
F=inline(char(y2),'x');
plot(x,F(x),'*m')
hold
off
|