problem with 'solve' function in matlab 2008 and upper

조회 수: 2 (최근 30일)
fsalehi
fsalehi 2011년 8월 24일
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
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.
fsalehi
fsalehi 2011년 8월 31일
would you please see my answer?

댓글을 달려면 로그인하십시오.

답변 (2개)

Kai Gehrs
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

fsalehi
fsalehi 2011년 8월 31일
I try Walter's recommendation but it didnt work in Matlan 2009 and 2010a. I'm not sure about 2011a.
I should note that, If I change values of Z, my solve commands works in all version of matlab..
I used these codes in my gui program and it should work in all version of matlab (at least 2009 and upper), but these codes didnt answer in 2009 and 2010a.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by