'Convert a MATLAB script into symbolic script to find the symbolic derivative
I have the following function in MATLAB.
function [curve_final] = RDM_FP(theta_in,T,t0)
Nf = length(T);
fs = 1/(T(2)-T(1));
that = T-t0;
pos_interval = that>0;
neg_interval = that<=0;
that = that(pos_interval);
%fitting parameters
alpha = theta_in(1);%parameter alpha from extended dispersion Tofts model alpha= a*Ktrans
gamma = theta_in(2)/60;%parameter gamma from extended dispersion Tofts model gamma=kep
kappa = theta_in(3);%parameter k from extended dispersion Tofts model (dispersion coefficient)
mu = theta_in(4); %parameter mu from extended dispersion Tofts model (Mean Transit Time parameter)
curve1(pos_interval) = sqrt(kappa./(2.*pi.*(that))).*exp(-kappa.*(that-mu).^2./(2.*(that)));
curve1(neg_interval) = 0;
curve2(pos_interval) = exp(-gamma.*(that));
curve2(neg_interval) = 0;
curve1 = [curve1 zeros(1,1000 -Nf)];
curve2 = [curve2 zeros(1,1000 -Nf)];
ft1 = fft(curve1);
ft2 = fft(curve2);
ft_total = ft1.*ft2;
curve= real(ifft(ft_total));
curve_final = 1/fs*alpha.*curve(1:Nf);
end
I want to convert this function into a symbolic script. I tried the following thing.
clear all,clc
syms theta_in [1 4] matrix
syms T [1 10]
syms t0
Nf = length(T);
fs = 1/(T(2)-T(1));
that = T-t0;
pos_interval = isAlways(that>0);
neg_interval = isAlways(that<=0);
that = that(pos_interval)
%fitting parameters
alpha = theta_in(1);%parameter alpha from extended dispersion Tofts model alpha= a*Ktrans
gamma = theta_in(2)/60;%parameter gamma from extended dispersion Tofts model gamma=kep
kappa = theta_in(3);%parameter k from extended dispersion Tofts model (dispersion coefficient)
mu = theta_in(4); %parameter mu from extended dispersion Tofts model (Mean Transit Time parameter)
curve1(pos_interval) = sqrt(kappa./(2.*pi.*(that))).*exp(-kappa.*(that-mu).^2./(2.*(that)));
curve1(neg_interval) = 0;
curve2(pos_interval) = exp(-gamma.*(that));
curve2(neg_interval) = 0;
curve1 = [curve1 zeros(1,1000 -Nf)];
curve2 = [curve2 zeros(1,1000 -Nf)];
ft1 = fft(curve1);
ft2 = fft(curve2);
ft_total = ft1.*ft2;
curve= real(ifft(ft_total));
curve_final = 1/fs*alpha.*curve(1:Nf);
However, I get the following error

I believe the problem lies in the line pos_interval = isAlways(that>0) since that is a symbol array and the condition cannot be evaluated for symbolic expressions. Can someone please provide some help. Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
