Symbolic dependency apparently sometimes gives wrong answers
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mohammad Shojaei Arani
il 28 Ott 2022
Commentato: Mohammad Shojaei Arani
il 29 Ott 2022
Hello,
I have a simple question but could not figour out how to tackle it by myself. Consider the following:
syms p1 y
f=[p1*y;p1];
hasSymType(f,'symfunDependingOn',y)
0
0
I am not happy with this since clearly I expected to get the answer [1,0]. I do not know why it behaves like this!!!
Please not that my actual problem are much more complicated and this is just to explain to you my question. So, please do not give me any answer which
just works for this simple example, rather I would like a generic sort of answer.
Any idea?
thanks in advance!
Babak
0 Commenti
Risposta accettata
Walter Roberson
il 28 Ott 2022
Not a bug. Your first element is a symbolic expression involving the desired variable, but symfundependingon is for unresolved symbolic functions that have the variable as a parameter.
syms f(x) g(x, y) h(y)
expressions involving f or g would be symfun depending on x, but h would not be.
7 Commenti
Steven Lord
il 28 Ott 2022
If you click on the three dots at the right side of the question, an answer, or a comment one of the options is Link. This will give you a hyperlink you can send to Support that the Support staff can use to see the discussion that's taken place here.
For example, if you click on this link you should be directed to the comment you made on John D'Errico's answer.
Più risposte (2)
John D'Errico
il 28 Ott 2022
Modificato: John D'Errico
il 28 Ott 2022
To be honest, this appears to be more of a bug report than anything else, since that option in hasSymType does not apprear to be working as per the documentation. So I would report it as such, but Answers is not the correct place to report bugs.
Could you find some other solution that would work? Even if someone could find something that works here, it does not get past the fact that hasSymType is the correct tool to solve your specidfic problem, and it should work as per the help.
Paul
il 28 Ott 2022
Hi Mohammad,
This works, at least for the examples cited in this comment. Haven't tested for anything but those examples.
syms x y z f(x,y)
F = @(expr,var) cellfun(@(s) any(has(s,var)),arrayfun(@(s) findSymType(s,'variable'),expr,'UniformOutput',false));
E = [x y f(x,y)] % then I expect to get the answer [1 0 1].
F(E,x)
E =[1 2 x^2;sin(x*y) x z] % then I expect to get the answer [0 0 1;1 1 0].
F(E,x)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!