problem with 'solve' function in matlab 2008 and upper
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a function in matlab, I want to find its maximum.. ( my function is guassian signal, it has a 2 pulse, I want to find extermum point of each pulse and calculate distance between their extermum).
base on this data, I used this commands:
syms t
Z=[0.000001116863592 0.000004972731239 -0.547213084010968 1.015860491921958]
alpha = 1.749262265091693e+013
Fc = 4.334354827118762e+006
phase2 = 0.991124769614895
phase1 = -0.549482979269295
solve(diff((Z(4).*exp(-alpha.*(t-Z(2)).^2).*cos(2*pi.*Fc.*(t-Z(2))+phase2))))-solve(diff((Z(3).*exp(-alpha.*(t-Z(1)).^2).*cos(2*pi.*Fc.*(t-Z(1))+phase1))));
this commands work in Matlab 2007a, but dont work in upper version. What should I do?
4 commentaires
Walter Roberson
le 30 Août 2011
You do not tell solve() what to solve for, and it is not going to be able to solve what you give if you give it in that order. You have to move the solve() command after the assignments. You should probably also use
tsol = solve(diff((Z(4).*exp(-alpha.*(t-Z(2)).^2).*cos(2*pi.*Fc.*(t-Z(2))+phase2))))-solve(diff((Z(3).*exp(-alpha.*(t-Z(1)).^2).*cos(2*pi.*Fc.*(t-Z(1))+phase1))), t);
to be sure that solve will solve for the variable t and return just that variable.
I am not certain at the moment why solve() is returning a 1x1 matrix. Try asking what the class() of the result is, and try asking what size() of it is. It might be a symbolic array of answers for which it happened to find only a single answer.
Réponses (2)
Kai Gehrs
le 30 Août 2011
Hi,
I agree with Walter's recommendation. I just would like to add that the results returned by solve are SYM objects and scalar SYM objects (including numbers) are displayed as 1x1 SYM objects in the workspace/variable browser. Maybe this is the root cause for your question.
I run your example in R2011a and without checking the details it seems to work fine.
Best regarrds,
-- Kai
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!