Help using solve function

5 visualizaciones (últimos 30 días)
Juan Pedro Martinez
Juan Pedro Martinez el 21 de Abr. de 2022
Respondida: David Hill el 21 de Abr. de 2022
Hello. I want to run the following code:
function [ema]=EMA(ec,fc,gamma,model)
if strcmp(model,'LL')==1
eh=1;
ema=solve((em-eh)/(em+gamma*eh)-sum(fc.*((ec-eh)./ec+gamma*eh))==0,em);
elseif strcmp(model,'MG')==1
eh=ec(fc==max(fc));
ema=solve((em-eh)/(em+gamma*eh)==sum(fc.*((ec-eh)./ec+gamma*eh)),em);
elseif strcmp(model,'B')==1
ema=solve(0==sum(fc.*((ec-em)./ec+gamma*em)),em);
end
I receive the following error:
Unrecognized function or variable 'em'.
I would think that solve assigns em as variable. I do not have the symbolic math toolbok yo use the function syms, which I have seen in some answers or documentation. Is there an alternative? I would guess so because solve does not require that toolbox.
If I try and replace the equation with a function handle as below I get the error
Operator '==' is not supported for operands of type 'function_handle'.
Thank you
fun=@(em) (em-eh)/(em+gamma*eh)-sum(fc.*((ec-eh)./ec+gamma*eh))
ema=solve(fun==0,em);

Respuestas (1)

David Hill
David Hill el 21 de Abr. de 2022
fun=@(em) (em-eh)/(em+gamma*eh)-sum(fc.*((ec-eh)./ec+gamma*eh));
guess=5;%what is your best guess for what ema should be?
ema=fzero(fun,guess);

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by