How can I generate a code for this equation?

 Akzeptierte Antwort

Manvi Goel
Manvi Goel am 10 Jun. 2019

0 Stimmen

You can use the following code for this
a = [429.494, 93.112, -6.050];
N = 1024;
temp = 0;
lambda = zeros(1, N)
for i = 1:N
for j = 1:3;
temp = temp + (a(j) * (((i - 1) / N - 1) ^ (j - 1)));
end
lambda(i) = temp;
temp = 0;
end
The lambda array will contain the final values.

Weitere Antworten (1)

Raj
Raj am 10 Jun. 2019

0 Stimmen

If you have Symbolic math toolbox then this can be done in an elegant way. In case you don't have symbolic math toolbox (like me) this code will do:
N=1024;
a=[429.494;93.112;-6.050];
wavelength=zeros(N,1);
for m=1:N
temp=zeros(3,1);
for n=1:3
temp(n,1)=a(n,1)*(((m-1)/(N-1))^(n-1));
end
wavelength(m,1)=sum(temp);
end

4 Kommentare

FSh
FSh am 10 Jun. 2019
with so many thanks because of your help but I got this error' Dimensions of arrays being concatenated are not consistent.'
Raj
Raj am 11 Jun. 2019
Bearbeitet: Raj am 11 Jun. 2019
At which line are you getting this error? I ran the code and I am not getting any error.
madhan ravi
madhan ravi am 11 Jun. 2019
It’s a homework obviously.
FSh
FSh am 11 Jun. 2019
Dimensions of arrays being concatenated are not consistent.
This is the error. not homework, that is a part of my data analysis.

Melden Sie sich an, um zu kommentieren.

Gefragt:

FSh
am 10 Jun. 2019

Kommentiert:

FSh
am 11 Jun. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by