Multiple Anonym Function return wrong values
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Pavel M
 el 20 de En. de 2022
  
    
    
    
    
    Respondida: Alan Stevens
      
      
 el 20 de En. de 2022
            Hello, I have a function that return 3 same values, but they must be different
C = [4622 5480 18923]*1e-12;
U = [454e3 454e3-20e3 20e3].*sqrt(2);
function W = Energy(C,U)
    f = 50;
    T = 1/f;
    t = [0:0.00001:T/4];
    fun = @(t) (U.^2/(2*1./(2*3.14*f*C)) * sin(2*2*3.14*f*t));
    fun2 =  @(C, U) (integral(fun, t(1), t(end)));
    for i = 1 : 3
        W(i) = fun2(C(i), U(i)) ;
    end
end
returned values are
w =
952.7728  952.7728  952.7728
What could be wrong in my code?
0 comentarios
Respuesta aceptada
  Alan Stevens
      
      
 el 20 de En. de 2022
        Here's one solution:
C = [4622 5480 18923]*1e-12;
U = [454e3 454e3-20e3 20e3].*sqrt(2);
W = Energy(C,U);
disp(W)
function W = Energy(C,U)
    f = 50;
    T = 1/f;
    for i = 1 : 3
        fun = @(t) (U(i).^2/(2*1./(2*3.14*f*C(i))) * sin(2*2*3.14*f*t));
        fun2 =  @(C, U) (integral(fun, 0, T/4));
        W(i) = fun2(C(i), U(i)) ;
    end
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

