Find fit with custom equation in Matlab - matlab

I'm trying to find a fit with a custom equation, but I keep getting errors and don't know why. The custom equation is really big. I'm using what I found here.
This is the code (sorry about the length of the custom equation):
myfittype = fittype('a + (b*2*y) + (c*2*x+dsqrt(6)(2*xy)) + (esqrt(3)*(2*x^2+2*y^2-1)) + (fsqrt(6)(x^2-y^2)) + (gsqrt(8)(3*x^2*y-y^3)) + (hsqrt(8)(3*x^2*y+3*y^3-2*y)) + (ipsqrt(8)(x^3+3*x*y^2-2*x)) + (jpsqrt(8)(x^3-3*xy^2)) + (ksqrt(10)*(4*x^3*y-4*xy^3)+lsqrt(10)*(8*x^3*y+8*x*y^3-6*xy)) + (msqrt(5)*(6*x^4+12*x^2*y^2+6*y^4-6*x^2-6*y^2+1)) + (nsqrt(10)(4*x^4+4*x^2*y^2-3*x^2-4*x^2*y^2-4*y^4+3*y^2)) + (osqrt(10)(x^4-6*x^2*y^2+y^4)) + (psqrt(12)(5*x^4*y-10*x^2*y^3+y^5)) + (qsqrt(12)(15*x^4*y-12*x^2*y-5*y^5+4*y^3+10*x^2*y^3)) + (rsqrt(12)(10*x^4*y+20*x^2*y^3+10*y^5-12*x^2*y-12*y^3+3*y)) + (ssqrt(12)(10*x^5+20*x^3*y^2+10*x*y^4-12*x^3-12*x*y^2+3*x)) + (tsqrt(12)(5*x^5-10*x^3*y^2-4*x^3-15*x*y^4+12*xy^2)) + (usqrt(12)*(x^5-10*x^3*y^2+5*x*y^4))',... 'independent',{'x'},'dependent',{'y'},...
'coefficients',{'a','b','c','d','e','f','g','h','ip','jp','k','l','m','n','o','p','q','r','s','t','u'})
Here is the code formatted with line breaks (...) so that you can read it:
myfittype = fittype('a + (b*2*y) + (c*2*x+d*sqrt(6)*(2*x*y)) + ...
(e*sqrt(3)*(2*x^2+2*y^2-1)) + (f*sqrt(6)*(x^2-y^2)) + ...
(g*sqrt(8)*(3*x^2*y-y^3)) + (h*sqrt(8)*(3*x^2*y+3*y^3-2*y)) + ...
(ip*sqrt(8)*(x^3+3*x*y^2-2*x)) + (jp*sqrt(8)*(x^3-3*x*y^2)) + ...
(k*sqrt(10)*(4*x^3*y-4*x*y^3)+l*sqrt(10)*(8*x^3*y+8*x*y^3-6*x*y)) + ...
(m*sqrt(5)*(6*x^4+12*x^2*y^2+6*y^4-6*x^2-6*y^2+1)) + ...
(n*sqrt(10)*(4*x^4+4*x^2*y^2-3*x^2-4*x^2*y^2-4*y^4+3*y^2)) + ...
(o*sqrt(10)*(x^4-6*x^2*y^2+y^4)) + (p*sqrt(12)*(5*x^4*y-10*x^2*y^3+y^5)) + ...
(q*sqrt(12)*(15*x^4*y-12*x^2*y-5*y^5+4*y^3+10*x^2*y^3)) + ...
(r*sqrt(12)*(10*x^4*y+20*x^2*y^3+10*y^5-12*x^2*y-12*y^3+3*y)) + ...
(s*sqrt(12)*(10*x^5+20*x^3*y^2+10*x*y^4-12*x^3-12*x*y^2+3*x)) + ...
(t*sqrt(12)*(5*x^5-10*x^3*y^2-4*x^3-15*x*y^4+12*x*y^2)) + ...
(u*sqrt(12)*(x^5-10*x^3*y^2+5*x*y^4))', ...
'independent',{'x'},'dependent',{'y'}, ...
'coefficients', ...
{'a','b','c','d','e','f','g','h','ip','jp','k','l','m','n','o','p','q','r','s','t','u'})
The error says this expression is not a valid matlab expression
Hope you can help me, thanks.

I run your code :
The problem of your code is that
Coefficient d does not appear in the equation expression.

Related

'range' cannot be used as a variable or function name

the error is:
Compilation error. Line 13: 'range' cannot be used as a variable or
function name.
//#version=5
indicator('My Script')
// 计算振幅
range = high - low
// 定义信息框显示的内容
info = "开盘价: " + tostring(open) + "\n"
+ "最高价: " + tostring(high) + "\n"
+ "最低价: " + tostring(low) + "\n"
+ "振幅: " + tostring(range) + "\n"
+ "成交量: " + tostring(volume)
// 定义当鼠标悬停在当前k线时显示信息框
bgcolor(not nz(bgcolor[1]) and barstate.ishovered, color.new(color.red, 50))
// 当鼠标悬停在当前k线时,显示信息框
label.new(bar_index, high, text=info, xloc=xloc.bar_time, yloc=yloc.abovebar
Your code is full of error.
For the range problem, just change :
range = high - low
To :
myrange = high - low

HTML String on Object Property Won't Update

I have an object constructor that sets some properties, and later uses them to concatenate a string to write to the DOM. I can see that this works in some cases, but not in others.
function Fighter(name, level, attackPts, defencePts, imgSource) {
// TRUNCATED PROPERTY ASSIGNMENTS AREA:
this.attackPts = attackPts;
this.defencePts = defencePts;
// DOM ELEMENT CONSTRUCTORS:
this.img = "style='background: #444 url(" + imgSource + ") no-repeat center'";
this.char_card_name = "<h3>" + this.name + "</h3>";
this.char_card_hitdef = "<h4>" + this.attackPts + "/" + this.defencePts + "</h4>";
this.char_card = "<div class='fighter " + faction + "' " + "id='" + this.name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>";
In a game function later on I modify the attack and defense points for this "Fighter" object, and that works as expected, and my console.log() tests verify that the concatenated properties also update . . . . up until the final string to pull it all together and display:
this.char_card = "<div class='fighter " + faction + "' " + "id='" + this.name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>";
When I log this property, those attack and defense numbers don't budge, even though they update successfully in the previous property, this.char_card_hitdef
What could I be overlooking here? I crawled all over the web looking for scope or variable reference issues, but my log statements bring me right back to this one pinching point.
Because you are still in the constructor, you need to refer to the variables without this. that are a parameter AND property of the Object Fighter.
So change
this.char_card = "<div class='fighter " + faction + "' " + "id='" + this.name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>";
to
this.char_card = "<div class='fighter " + faction + "' " + "id='" + name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>"
And all other properties that refer to properties above them.
You can read more about constructors here

Retargeting in Fb,Google

I have a campaign and pixel Id for Fb and Google both which looks something like this.
Can some one tell me how can I implement retargeting pixel in FB, google. What are the changes do I need to make in this dynamicaly generated Pixel script?
PixelScript = PixelScript + "<script>(function(){" + Environment.NewLine +
"window._fbds = window._fbds || {};" + Environment.NewLine +
"_fbds.pixelId = " + FB_Pixel + ";" + Environment.NewLine +
"var fbds = document.createElement(\"script\");" + Environment.NewLine +
"fbds.async = true;" + Environment.NewLine +
"fbds.src = \"//connect.facebook.net/en_US/fbds.js\";" + Environment.NewLine +
"var s = document.getElementsByTagName(\"script\")[0];" + Environment.NewLine +
"s.parentNode.insertBefore(fbds, s);" + Environment.NewLine +
"})();" + Environment.NewLine +
"window._fbq = window._fbq || [];" + Environment.NewLine +
"window._fbq.push([\"track\", \"PixelInitialized\", {}]);" + Environment.NewLine +
"</script>" + Environment.NewLine +
"<noscript><img height=\"1\" width=\"1\" border=\"0\" alt=\"\" style=\"display:none\" src=\"https://www.facebook.com/tr?id=" + FB_Pixel + "&ev=NoScript\" /></noscript>";
The given pixel is enough to drop cookies on the website. No need to add anything.

Enforcing a rule in a symbolic expression in Matlab

I have already asked the same question in the Matlab user community.
I have the following symbolic expression:
(3*s11)/2 + (3*s12)/2 + (3*s13)/2 + (3*s14)/2 + (3*s15)/2 + (s11*s12)/2 + (s11*s13)/2 + (s11*s14)/2 + (s12*s13)/2 + (s11*s15)/2 + (s12*s14)/2 + (s12*s15)/2 + (s13*s14)/2 + (s13*s15)/2 + (s14*s15)/2 + s11^2/4 + s12^2/4 + s13^2/4 + s14^2/4 + s15^2/4 + 9/4
It is stored as a symbolic expression variable. I would like to enforce the rule sij^2 = 1 i.e. the variables can be either -1 or +1. If I enforce the rule in the expression mentioned above, the expression will be as follows.
(3*s11)/2 + (3*s12)/2 + (3*s13)/2 + (3*s14)/2 + (3*s15)/2 + (s11*s12)/2 + (s11*s13)/2 + (s11*s14)/2 + (s12*s13)/2 + (s11*s15)/2 + (s12*s14)/2 + (s12*s15)/2 + (s13*s14)/2 + (s13*s15)/2 + (s14*s15)/2 + 1/4 + 1/4 + 1/4 + 1/4 + 1/4 + 9/4
How can I do this in Matlab?
Set assumptions e.g. assume(s14^2==1), then use simplify.

Simplifying Boolean Expression (A'BC) + (A'B'C) + (A'BC) + (AB'C)

please help me with simplifying this one. I am a bit new to these..
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
the book i use shows and answer, which is,
Answer = A'B + B'C
I tried simplifying, but I get stucked with two eXors, my simplification so far goes like this...
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
A (BC' + B'C) + C (A'B + AB')
This doesn't seem to be a write way, Please someone help me simplify this, and please show step by step, as I am sort of new..
Also I don't get how to simplify eXor further..
You have the Rule X' + X = True. SO
(A'BC') + (A'B'C) + (A'BC) + (AB'C) =
(A'BC') + (A'BC) + (A'B'C) + (AB'C) = // just permuting the terms
A'B(C' + C) + (A' + A)B'C = // factoring
A'B + B'C
I'll assume that multiplcation is AND, addition is OR and prime is negation.
Here's what I'd do:
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
A'B(C'+C) + B'C(A'+A)
(C'+C) = 1 and (A'+A) = 1
A'B + B'C
Q.E.D.
for simplifying boolean expressions use karnaugh maps. i think it is very much useful if we less number of variables. but if we have more variables then we can follow methods because this method is not that preferable.
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
answer just arrange the terms like this
step 1:A'BC'+A'BC+AB'C+A'B'C
now get common terms out
step 2 : A'B(C'+C)+B'C(A+A')
step 3 : A'B.1+B'C.1
step 4 : A'B+B'C