Writing short function that uses function handle in output?

6 ビュー (過去 30 日間)
Dinkleberg
Dinkleberg 2018 年 6 月 18 日
I'm attempting to write a function in MATLAB that will output out the double series formula (seen in comment below as well as the image below, ignoring the z and phi terms)
In short, what I would like for this function to do is to take in an integer number of k and n as arguments in and generate a formula containing unknown parameters A(k,n), theta(k), and theta(n) that I can eventually solve for using lsqcurvefit(). Right now, all the current function outputs is:
@(A,t)A(ik,in).*(cos((2*pi*ik*Vs*t)/lambda+thetak(ik)).*cos((2*pi*in*t)/tau+thetan(in)))
Is this because of the function handle? Is there a more efficient way for me to translate my formula into code?
fun = genfunction(k,n)
% WIP as of 6/18: long stretch goal is to have this also output an array of
% x0 guesses:
% [formula, x0] = genfunction(k,n)
%Takes number of k and n to generate formula in the form:
% sum(k=1 to k)sum(n=1 to n)A(k,n)cos(2pi*k*Vs*t/lambda+theta(k))*cos(2pi*n*t/tau+theta(n))
Vs = 7.6; %m/s
lambda = 20; %m
tau = 20; %s
A = zeros(k,n);
thetak = zeros(1,k);
thetan = zeros(1,n);
%fun = @(A,t)A*(cos((2*pi*Vs*t)/lambda + thetak)*cos((2*pi*t)/tau + thetan));
fun = 0;
for ik=1:k
for in=1:n
fun = @(A,t) A(ik,in).*(cos((2*pi*ik*Vs*t)/lambda + thetak(ik)).*cos((2*pi*in*t)/tau + thetan(in)));
end
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeFunctional Programming についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by