% Programme for estimating k in DE
prompt= 'input a value for k : ' ;
k = input(prompt);
w =(pi/12);
n=1:100;
k(n+1)=-1*(log(((12*(((k(n))^2)+(w^2))-(5*k(n))*(k(n)*cos(6*w))+(wsin(6*w)))/(17*((k(n)^2)+(w^2))-5*k(n)*(k(n)*cos(5*w))+(w*sin5w)));
disp (k)
the problem seems to be with the semicolon after the log funtion

2 Kommentare

Walter Roberson
Walter Roberson am 10 Feb. 2016
You have not indicated what the error is.
Is the user entering a vector or a scalar?
Is k(n) intended to indicate k indexed at n, or k multiplied by n?
Hint: .^ .* ./
reuben crockett
reuben crockett am 10 Feb. 2016
a scalar and k indexed at n the error just says missing parenthases

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 10 Feb. 2016
Bearbeitet: Star Strider am 10 Feb. 2016

0 Stimmen

The problem is most likely that you are missing several operators (probably multiplication operators), as well as vectorising it here:
k(n+1)=-1*(log(((12*(((k(n))^2)+(w^2))-(5*k(n))*(k(n)*cos(6*w))+(wsin(6*w)))/(17*((k(n)^2)+(w^2))-5*k(n)*(k(n)*cos(5*w))+(w*sin5w)));
See if substituting this helps:
k(n+1)=-1*(log(((12*(((k(n))^2)+(w.^2))-(5*k(n))*(k(n)*cos(6*w))+(w.*sin(6*w)))./(17*((k(n)^2)+(w.^2))-5*k(n)*(k(n)*cos(5*w))+(w.*sin(5*w))));
The parentheses don’t match, so you will need to fix that before you run this line. (I don’t know what you’re doing, so I can’t fix them for you.)

2 Kommentare

reuben crockett
reuben crockett am 10 Feb. 2016
cheers im basically trying to re write an equation into matlab the one found at the top of page 66 of this document
It’s easiest to break the statement out into its constituent parts. That makes it easier to read, and easier to troubleshoot:
N = 12*(k(n)^2 + w.^2) - 5*k(n)*(k(n)*cos(6*w) + w.*sin(6*w));
D = 17*(k(n)^2 + w.^2) - 5*k(n)*(k(n)*cos(5*w) + w.*sin(5*w));
k(n+1) = -log(N./D);
The computer has to do all these calculations and command parsing anyway, so you’re not losing any efficiency by creating the separate variables.
You also need to understand the vectorisation I used in those statements. See the documentation on Array vs. Matrix Operations for all the interesting details.
I ran a version of it to be sure it works. (It does.) I leave the rest to you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by