How to write in Matlab a matrix whose coefficients depend on a real alpha parameter
1 view (last 30 days)
Show older comments
A(i,j) = (1+alpha*x(i)*y(j))*exp(x(i)*y(j))
where almpha is a real parameter, x(i) and y(j) points in [0 , 1] with i , j = 1, ..., N
0 Comments
Accepted Answer
John D'Errico
on 26 Mar 2024
Edited: John D'Errico
on 26 Mar 2024
Many ways. It seems unclear exactly what is your goal. And what are x and y? Are they just a list of numbers? Or a sequence as linspace would provide?
For example, you might do this:
N = 4;
x = linspace(0,1,N);
y = linspace(0,1,N);
syms alpha
A = (1+alpha*x.'*y)*exp(x.'*y)
vpa(A,5)
Of course, x and y might be just any arbitrary vectors of numbers.
Another approach would be to write it as a function handle. This time I'll use random vectors for x and y.
x = sort(rand(1,N))
y = sort(rand(1,N))
Afun = @(alph) (1+alph*x.'*y)*exp(x.'*y);
And now we can evaluate Afun for any value of the parameter.
Afun(0.3)
More Answers (1)
Voss
on 26 Mar 2024
Here's an example:
alpha = 0.4;
N = 9;
x = linspace(0,1,N);
y = linspace(0,1,N);
xy = x(:).*y(:).' % column x * row y
A = (1+alpha.*xy).*exp(xy)
0 Comments
See Also
Categories
Find more on Line Plots 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!