Asked by engineer
on 23 May 2019 at 12:56

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!!

Answer by Adam Danz
on 23 May 2019 at 15:43

Accepted Answer

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

engineer
on 23 May 2019 at 19:05

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
on 23 May 2019 at 19:54

Besides, how do you save the each x variable within loop in the code you provided?

Adam Danz
on 23 May 2019 at 20:08

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/463662-how-to-solve-equation-for-a-given-matrix#comment_707990

## engineer (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/463662-how-to-solve-equation-for-a-given-matrix#comment_708003

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/463662-how-to-solve-equation-for-a-given-matrix#comment_708004

## engineer (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/463662-how-to-solve-equation-for-a-given-matrix#comment_708005

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/463662-how-to-solve-equation-for-a-given-matrix#comment_708007

Sign in to comment.