problem with 'solve' function in matlab 2008 and upper
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2011-8-30
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.
回答(2 个)
Kai Gehrs
2011-8-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!