i want to write equation in matlab

1 view (last 30 days)
% ampiltude
function[sign]=amplitude(t,x,y)
sign = 2*A(x^2+y^2)*exp(-0.5*((r/p)^2+(t/T)^2));
end
% function
% theta
Theta = @(x,y)atan(y/x);
K=1;
U_txy = Amp(t+T/2,x,y)*exp(iS*Theta)*exp(i*K*t)+Amp(t-T/2,x,y)*exp(iS*Theta)*exp(-i*K*t);
i want to write the above eqautions in matlab.that is my atempt. code wont run. doubt its ok. the function is suspose to be the amplitude, sign.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Apr 2021
format long g
x = randn, y = randn, t = 1.2;
x =
0.377605597049117
y =
-1.54538132450563
U(x,y,t)
ans =
-1.62600857320088e-05 - 3.8121853905296e-06i 7.54974455191625e-06 - 1.31539198710771e-06i
function U_txy = U(x,y,t) %need this in order to have shared constants
K = 1;
A = 7;
rho = 0.3;
t0 = 0.81;
tau = 1.28;
S = -2.16;
Theta = @(x,y)atan2(y,x);
r = reshape(sqrt(x.^2+y.^2), [], 1);
th = reshape(Theta(x,y), [], 1);
U_txy = amplitude(r,t+t0/2).*exp(1i.*S.*th).*exp(1i*K*t) + ...
amplitude(r,t-t0/2).*exp(1i.*S.*th).*exp(-1i*K*t).*exp(1i.*th.*[-1 1]);
% amplitude
function sign = amplitude(r,t)
sign = A .* r.^abs(S) .*exp(-0.5*((r./rho).^2 + (t./tau).^2));
end
end

More Answers (0)

Categories

Find more on Price and Analyze Financial Instruments in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!