how to solve equation for a given matrix

Hi everybody
I have got equation which is ;
Eq = 0.4075*exp(-((e-14.87)/11.39).^2) + 0.5621*exp(-((e-18.64)/27.74).^2);
e is a 100*1 double matrix.
I would like to use the value of each row as an input to my function and save the results as matrix again. I used solve command, I could get any results.
Any suggestion is highly appreciated.
Thanks!!

5 commentaires

madhan ravi
madhan ravi le 23 Mai 2019
just loop through e and solve the equations?
engineer
engineer le 23 Mai 2019
thanks for the answer. Can you show or refer me an axample ?
madhan ravi
madhan ravi le 23 Mai 2019
Ah sorry which variable are you the solving for?, you say you already have e in hand?
engineer
engineer le 23 Mai 2019
Yes I have it 'e' as 100*1 double matrix. I just need to implement each value into the function and obtain the results as another matrix.
e = .... 100 X 1 values
Eq = 0.4075*exp(-((e-14.87)/11.39).^2) + 0.5621*exp(-((e-18.64)/27.74).^2); % doesn't this get you the required results?

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 23 Mai 2019
What's wrong with what you've already got?
%Vector method
e = rand(100,1)*10;
Eq = 0.4075*exp(-((e-14.87)/11.39).^2) + 0.5621*exp(-((e-18.64)/27.74).^2);
% Loop method
Eq2 = zeros(size(e));
for i = 1:numel(e)
Eq2(i) = 0.4075*exp(-((e(i)-14.87)/11.39).^2) + 0.5621*exp(-((e(i)-18.64)/27.74).^2);
end
% Are they equal?
isequal(Eq,Eq2) % = 1; yes

11 commentaires

engineer
engineer le 23 Mai 2019
it worked, thank you very much.
engineer
engineer le 23 Mai 2019
I have one more question. my matrix 'e' is not in the x axis. It is actually in the y axis. How can I implement my matrix in y axis and find the corresponding X axis and save it as a matrix?
Adam Danz
Adam Danz le 23 Mai 2019
I'm sorry, I don't follow the question. What do you mean by x axis and y axis?
engineer
engineer le 23 Mai 2019
matrix 'e' is output for the function. Therefore, I would like to find the input matrix.
For example:
a = [2;5;7]
a(i) = 2x+5
in this case the answer :
x =[9;15;19]
I hope it is clearer now.
But 'e' is an input variable in your example. Eq is the output.
Do you mean you're trying to solve for this:
e = 0.4075*exp(-((x-14.87)/11.39).^2) + 0.5621*exp(-((x-18.64)/27.74).^2);
where x is unknow and e is known?
engineer
engineer le 23 Mai 2019
yes, exactly.
engineer
engineer le 23 Mai 2019
any suggestion? , I got really stucked here?
Try this out
syms x
for i = 1:numel(e)
sol(i) = solve(0.4075*exp(-((x-14.87)/11.39).^2) + 0.5621*exp(-((x-18.64)/27.74).^2) == e(i));
end
I received this error.
Warning: Unable to find explicit solution. For options, see help.
> In solve (line 317)
Subscripted assignment dimension mismatch.
Error in sym/privsubsasgn (line 1107)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 944)
C = privsubsasgn(L,R,inds{:});
engineer
engineer le 23 Mai 2019
Modifié(e) : engineer le 23 Mai 2019
Besides, how do you save the each x variable within loop in the code you provided?
Adam Danz
Adam Danz le 23 Mai 2019
sol(i) is the x values that satisfy the function. If you search for that warning within this forum you get lot's of feedback.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by