Help using solve function

1 Ansicht (letzte 30 Tage)
Juan Pedro Martinez
Juan Pedro Martinez am 21 Apr. 2022
Beantwortet: David Hill am 21 Apr. 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);

Antworten (1)

David Hill
David Hill am 21 Apr. 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);

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by