Defining and plotting 2 parametric functions
Afficher commentaires plus anciens
I'm new to Matlab, I defined the following functions:
function L1 = Like1(y)
P0 = 1/(2*pi*0.6)*exp(-1/(2*0.36)*(x^2+y^2-2*0.8*x*y));
P1 = 1/(2*pi*1)*exp(-1/(2*1)*(x^2+y^2));
L1 = int(P1,x,-inf,0)/int(P0,x,-inf,0);
end
function L2 = Like2(y)
P0 = 1/(2*pi*0.6)*exp(-1/(2*0.36)*(x^2+y^2-2*0.8*x*y));
P1 = 1/(2*pi*1)*exp(-1/(2*1)*(x^2+y^2));
L2 = int(P1,x,0,+inf)/int(P1,x,0,+inf);
end
function I1 = Int1(y)
P0 = 1/(2*pi*0.6)*exp(-1/(2*0.36)*(x^2+y^2-2*0.8*x*y));
I1 = int(P0,x,-inf,0);
end
function I2 = Int2(y)
P0 = 1/(2*pi*0.6)*exp(-1/(2*0.36)*(x^2+y^2-2*0.8*x*y));
I2 = int(P0,x,0,+inf);
end
function I3 = Int3(y)
P1 = 1/(2*pi*1)*exp(-1/(2*1)*(x^2+y^2));
I1 = int(P1,x,-inf,0);
end
function I4 = Int4(y)
P1 = 1/(2*pi*1)*exp(-1/(2*1)*(x^2+y^2));
I2 = int(P1,x,0,+inf);
end
and I'm trying to plot the following two functions:
function alpha = error1(T)
syms y;
alpha = int(Int1(y),y,solve(Like1(y)>T,y))+ int(Int2(y),y,solve(Like2(y)>T,y));
end
function beta = error2(T)
syms y;
beta = int(Int3(y),y,solve(Like1(y)<T)) + int(Int4(y),y,solve(Like2(y)<T))
end
I have 2 questions , when I run this function editer, I keep getting the error "Undefined function or variable 'T'".
Once I solve this issue, what would be the next step to plot error2(T) vs. error1(T).
5 commentaires
Walter Roberson
le 22 Mai 2015
Exactly what are you running in the function editor? How are you "running" in the function editor?
Walter Roberson
le 22 Mai 2015
In your functions, x is undefined. The context suggests that you need a
syms x
in each of them.
Walter Roberson
le 22 Mai 2015
In Like2 you have
L2 = int(P1,x,0,+inf)/int(P1,x,0,+inf);
that is dividing something by itself, so the result is always going to be 1. Perhaps you wanted the numerator to be P0 instead of P1.
Question: is it the case that the P0 and P1 in Like1 and Like2 are exactly the same expressions?
Maggie Mhanna
le 24 Mai 2015
Modifié(e) : Maggie Mhanna
le 24 Mai 2015
Walter Roberson
le 24 Mai 2015
[Merging from a duplicate post], Maggie wrote,
I defined the following functions:
function alpha = error1(T)
syms x y
P0 = 1/(2*pi*0.6)*exp(-1/(2*0.36)*(x^2+y^2-2*0.8*x*y));
P1 = 1/(2*pi*1)*exp(-1/(2*1)*(x^2+y^2));
L1 = int(P1,x,-inf,0)/int(P0,x,-inf,0);
L2 = int(P1,x,0,+inf)/int(P0,x,0,+inf);
I1 = int(P0,x,-inf,0);
I2 = int(P0,x,0,+inf);
alpha = int(I1,y,L1>T)+ int(I2,y,L2>T);
end
function beta = error2(T)
syms x y
P0 = 1/(2*pi*0.6)*exp(-1/(2*0.36)*(x^2+y^2-2*0.8*x*y));
P1 = 1/(2*pi*1)*exp(-1/(2*1)*(x^2+y^2));
L1 = int(P1,x,-inf,0)/int(P0,x,-inf,0);
L2 = int(P1,x,0,+inf)/int(P0,x,0,+inf);
I1 = int(P1,x,-inf,0);
I2 = int(P1,x,0,+inf);
beta = int(I1,y,L1<T)+ int(I2,y,L2<T);
end
I don't if there's a problem in the expressions of alpha and beta, but what I mean is that Im trying to integrate I1 for example over the domain L1(y) < T.
After that I defined:
t = 0:0.01:30;
y1 = error1(t);
I get the following error:
Error using mupadmex
Error in MuPAD command: The argument is invalid. [Dom::Interval::new]
Error in sym/int (line 124)
rSym = mupadmex('symobj::intdef',f.s,x.s,a.s,b.s,options);
Error in error2 (line 10)
beta = int(I1,y,L1<T)+ int(I2,y,L2<T);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 2-D Function Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!