Help using solve function

1 view (last 30 days)
Juan Pedro Martinez
Juan Pedro Martinez on 21 Apr 2022
Answered: David Hill on 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);

Answers (1)

David Hill
David Hill on 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);

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!