How to write in Matlab a matrix whose coefficients depend on a real alpha parameter

9 vues (au cours des 30 derniers jours)
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

Réponse acceptée

John D'Errico
John D'Errico le 26 Mar 2024
Modifié(e) : John D'Errico le 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)
A = 
vpa(A,5)
ans = 
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))
x = 1x4
0.0962 0.1445 0.9101 0.9192
y = sort(rand(1,N))
y = 1x4
0.0370 0.2099 0.4181 0.4717
Afun = @(alph) (1+alph*x.'*y)*exp(x.'*y);
And now we can evaluate Afun for any value of the parameter.
Afun(0.3)
ans = 4x4
4.1115 4.5130 5.0803 5.2430 4.1284 4.5323 5.1030 5.2666 4.3969 4.8383 5.4627 5.6418 4.4000 4.8419 5.4670 5.6462

Plus de réponses (1)

Voss
Voss le 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
xy = 9x9
0 0 0 0 0 0 0 0 0 0 0.0156 0.0312 0.0469 0.0625 0.0781 0.0938 0.1094 0.1250 0 0.0312 0.0625 0.0938 0.1250 0.1562 0.1875 0.2188 0.2500 0 0.0469 0.0938 0.1406 0.1875 0.2344 0.2812 0.3281 0.3750 0 0.0625 0.1250 0.1875 0.2500 0.3125 0.3750 0.4375 0.5000 0 0.0781 0.1562 0.2344 0.3125 0.3906 0.4688 0.5469 0.6250 0 0.0938 0.1875 0.2812 0.3750 0.4688 0.5625 0.6562 0.7500 0 0.1094 0.2188 0.3281 0.4375 0.5469 0.6562 0.7656 0.8750 0 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 1.0000
A = (1+alpha.*xy).*exp(xy)
A = 9x9
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0221 1.0446 1.0676 1.0911 1.1150 1.1395 1.1644 1.1898 1.0000 1.0446 1.0911 1.1395 1.1898 1.2422 1.2967 1.3534 1.4124 1.0000 1.0676 1.1395 1.2157 1.2967 1.3826 1.4738 1.5706 1.6732 1.0000 1.0911 1.1898 1.2967 1.4124 1.5377 1.6732 1.8199 1.9785 1.0000 1.1150 1.2422 1.3826 1.5377 1.7088 1.8976 2.1058 2.3353 1.0000 1.1395 1.2967 1.4738 1.6732 1.8976 2.1499 2.4335 2.7521 1.0000 1.1644 1.3534 1.5706 1.8199 2.1058 2.4335 2.8089 3.2385 1.0000 1.1898 1.4124 1.6732 1.9785 2.3353 2.7521 3.2385 3.8056

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by