vendredi 28 décembre 2018

How to apply a equation to specific rows in a matrix

If I have a matrix m like,If I have a matrix m like:,If I have a matrix m like:

m=[0   340.216815000000
1.56250000000000    570.718050000000
4.68750000000000    769.256473000000
7.81250000000000    1176.42951000000
10.9375000000000    1632.88855600000
18.4375000000000    2099.99990500000
25.9375000000000    2099.99990500000
33.4375000000000    2099.99990500000
40.9375000000000    2099.99990500000
48.4375000000000    2099.99990500000
0   331.115127000000
1.53698699999995    510.419428000000
4.61084000000005    719.346166000000
7.68469200000004    1145.58672900000
10.7585449999999    1583.81915100000
18.1358640000001    2099.99990500000
25.5130620000000    2099.99990500000
32.8903809999999    2099.99990500000
40.2675780000000    2099.99990500000
47.6448969999999    2099.99990500000];

and a matrix n like:

n=[0    159.846351000000
1.52099599999997    343.757153000000
4.56286599999999    412.372440000000
7.60473600000000    926.872313000000
10.6466060000000    1063.47274800000
17.9471440000000    1079.82945400000
25.2475589999999    1200.00004800000
32.5480960000000    1200.00004800000
39.8486330000001    1200.00004800000
47.1491699999999    1200.00004800000
0   186.247796000000
1.49536100000000    386.090606000000
4.48608399999989    477.258742000000
7.47680700000001    775.100648000000
10.4676509999999    1004.91941000000
17.6453859999999    1075.44088400000
24.8232419999999    1200.00004800000
32.0009769999999    1200.00004800000
39.1787110000000    1200.00004800000
46.3565670000000    1200.00004800000];

how to build a vector E which matches that when m(:,1) is lower than 10, then use this formula:

(m(:,2).^2).*(3*(n(:,2).^2));

and when 10 < m(:,1) <= 25, use:

(m.*2)

the results would be this:

E = [8872341649.18581
115469679048.928
301885906398.286
3566916094097.57
3265.77711200000
4199.99981000000
4199.99981000000
4199.99981000000
4199.99981000000
4199.99981000000
662.230254000000
1020.83885600000
1438.69233200000
2291.17345800000
3167.63830200000
4199.99981000000
4199.99981000000
4199.99981000000
4199.99981000000
4199.99981000000];

Aucun commentaire:

Enregistrer un commentaire