Franco
Franco

Reputation: 87

symbolic calculus in MATLAB

I cannot find a way to define this equation in MATLAB:

formula

where the 'subs' n and m are related to the length of the vector Delta and L (I've read some help reference about 'symprod' and 'symsum' but I think they are not appropriate in this case).

What's the best way to handle these kind of equations in order to find, for example, the symbolic derivative or just the solution (given the parameters)?

Upvotes: 2

Views: 80

Answers (1)

m.s.
m.s.

Reputation: 16324

In order to define such a symbolic function I'd built it iteratively. Since from your formula it is not clear to me, I assume delta is a numerical vector of size N. I also left out function L, but you should get the idea:

syms t;

% define a demo function and random inputs
F = symfun(2*t, t);
% length of delta
N=5;
delta = randi(10,N,1);


% build function P(t) iteratively

% build the sum
s = 0;
for n=1:N
    % build the product
    p = 1;
    for m=1:n
        p = p*(1+delta(m)*(F));
    end
    s = s + delta(n)/p;
end

% build the final function
P = 1+(F(0) + F)*s;

You can then evaluate or differentiate P(t):

P(1.234)
dP = diff(P)

Upvotes: 1

Related Questions